Mark a spot 2 inches above and below the popped nail with a pencil. You will be adding additional nails here to secure the drywall to the stud.
Drive a nail in each of the spots you marked, using a hammer to pound until a small dimple forms as the nail head sinks below the surface of the drywall. Sinking the nails below the drywall allows you to add patching plaster and sand the area smooth, creating a seamless surface.
Pound the popped nail back into place with a hammer. The drywall probably worked loose around this nail when it popped out of the stud. Pounding it back in will not help secure the drywall to the stud, that is what the additional nails are for. Pounding this nail back in allows you to create a smooth, professional patch job.
Brush away any dust or loose paint you stirred up by pounding in the nails.
Spread patching plaster on the entire area, using a wide putty knife. Keep spreading until it is smooth and blends with the surrounding wall. Allow the patching plaster to dry completely before proceeding.
Sand the patching plaster with 150-grit sandpaper. When you finished, the patch should blend seamlessly with the wall. Brush away patching dust.
Touch up the area around the popped nail with wall paint. Use your brush to blend the paint into the surrounding area so there is no visible line where you painted once it dries. Two coats should provide adequate coverage.