A dog who tumbled down an oceanside cliff in San Francisco and became stranded on a narrow ledge 40 feet below was miraculously rescued thanks to the quick response of firefighters and a police drone operator, according to The Associated Press.

The accident occurred during a playful moment with another canine at Fort Funston, a scenic park perched atop bluffs up to 200 feet high. The dog, who was not familiar with the area, lost his footing on some vegetation and fell over the edge; fortunately, he managed to come to a rest on a small rocky shelf partway down the cliffside.

Firefighters then responded promptly to the scene and were assisted by a police drone operator who provided them with footage of the dog’s location.

After the team got into position and set up a “high-angle rigging system,” one firefighter was lowered by rope to the dog, where she secured a harness around him, picked him up, and held him close as they were lifted to safety together.

Once back on solid ground, the uninjured dog showed his gratitude to rescuers before being reunited with his guardian.

“He was happy,” San Francisco Fire Department Rescue Captain Samuel Menchaca said. “He knew he got rescued. He was wagging his tail. He was giving everyone kisses.”

Lady Freethinker is grateful to San Francisco firefighters and the police drone operator for their swift response and teamwork, which turned a potentially tragic situation into a heartwarming rescue.