Remove the nail or screw using the hammer claw or screwdriver. Use care to not damage the wall.
Replace the nail or screw with drywall screws. Do not use the old hole, but screw one in about an inch above and below the old screw hole, being sure it goes into the stud behind. Set the screw just slightly below the drywall surface, but don't tear the paper.
Fill the old hole and cover the new screw with a joint or spackling compound. Use a putty knife to push the compound into the hole. It should be slightly raised from the surface if applied correctly. Allow it to dry.
Sand the compound with a fine-grit sandpaper to smooth out the surface.