Cut around the edges of the hole with a drywall saw to make a square or rectangular hole. If the original hole is larger than 10 inches in diameter, cut the drywall all the way back to the rafters on either side, then trim the edges with a utility knife so that half the face of the rafter is exposed on either side.
Install a piece of scrap wood behind the drywall to provide a surface for screwing on a drywall patch. If you have cut back to the rafters, fit a piece of 2-by-4 lumber between the rafters so that it spans the center of the opening and screw this to the rafters with drywall screws. This will be easier if you can work in the attic, but you can also do it by working under the ceiling.
Use plywood to provide a backing for a smaller hole. Cut a strip of plywood that spans the hole, is thin enough to fit through it, and extends past the edges about 2 inches. Drive a drywall screw partially into the center and set the plywood inside the ceiling so it sits on the drywall and partially covers the hole. Hold it down with the partially-driven screw while you drive screws into the drywall at the edges of the hole and into the plywood to hold it in place. When it is secure, remove the screw from the center.
Cut a piece of drywall to fit in the hole with a utility knife or drywall saw and screw it to the backing. If the hole is large, be sure to screw this patch into the rafters at the edges.
Spread mud along the edges of the patch and into the holes made by the screw heads with a drywall blade. Moisten some paper drywall tape and spread it on top of the mud along the edges, then scrape the tape flat with the blade, removing excess mud and saving it for later. Let the mud dry overnight.
Cover the tape joints and screw heads with a second coat of mud, and scrape this flat, feathering the edges into the ceiling. Let the mud dry, and spread a third coat. Feather the third coat with a 6 inch blade to hide the repair and blend it into the ceiling.
Sand the repair lightly after it has dried and paint it with drywall primer prior to painting on the ceiling color.