When reassembling your iMac, be very careful to align the exterior I/O ports correctly. The logic board can sit crooked even when secured with all its screws.
Use a USB flash drive and/or ethernet cable to keep the logic board seated correctly while you tighten the screws.
Lift the RAM module to an angle of about 30 degrees and slide it out.
When handling the RAM module, touch only the outside edges. Take care not to touch the gold-colored contact points along the bottom edge.
To install a new RAM module, slide it in place at about the same angle until it is snug, and then swing it downward until the two clips snap into place.
Peel off the four black tamper-evident stickers covering the heat sink mounting screws.
Remove the four T10 screws that secure the heat sink from the backside of the logic board.
During reassembly, tighten these screws one full turn at a time, alternating in a cross pattern. This will gradually increase the clamping pressure evenly across the surface of the CPU. Continue gradually tightening the screws until they're snug and the entire spring plate lays flat against the logic board.
Note that the CPU will most likely remain stuck to the underside of the heat sink as it's lifted out. Take care not to damage it.
Lift and remove the heat sink assembly from the logic board.
When reassembling your iMac, remove the CPU from the heat sink and reinstall it separately from the heat sink. This will make sure it's installed correctly and prevent damage.
Re” I did it. Everything went very well, but the two thunderbolt plugs are not working after all. LAn and USb is doing well. Any suggestions about it?” You need to disassemble the iMac again to the point where the logic board is loose (step 58-59 on this guide). Connect a thunderbolt cable, a USB cable and and ethernet cable to the back of the iMac with the logic board in place but the logic board screws not tightened. This will ensure the ports are correctly lined. Tighten the logic board screws and finish the reassembly (at this point you can disconnect the cables.) . This should solve the problem.