Cut out the entire damaged area with a utility knife. Try to do this with just one cut on each side and avoid cutting through the carpet pad.
Use the cut-out piece as a pattern to cut a new piece. Be sure to match the direction of the pile.
Spread carpet adhesive on the exposed carpet pad and on the back of the patch itself.
Put some adhesive under the edges of the carpet surrounding the hole as well.
Press the patch into the hole and rough up the pile with your fingertips.
Let the glue dry for about six hours and then vacuum the patched area.