Firefighters had to smash through concrete blocks with a sledgehammer to free a seven-stone (44kg) Rottweiler who was wedged between two walls.
Eighteen-month-old Chloe became trapped in the seven-inch (18cm) wide space at Butts Road, Sholing, Hampshire.
She had been stuck for three hours and had even started gnawing at the wall in a desperate attempt to escape.
However, the dog was released unharmed after fire crews knocked a hole through the block work.
Anton Phillips, of Hampshire Fire and Rescue Service, said: "Once the operation started to remove the block wall from her left hand side she was out in about 15 minutes."
The dog's owners believe Chloe was playing when she ran into a corner in their garden that forms a boundary between two neighbouring houses.
Firefighters first slid casualty shields between the dogs' sides and the walls, equipment used to protect car crash victims, and tried to free her with washing-up liquid as a lubricant.
After this failed, an RSPCA officer and the dog's owners kept her calm as they knocked a hole in one of the walls.
Mr Philips said: "Dog entrapments are extremely difficult and dangerous operations because they do get stressed quite quickly and can become aggressive."