A giant panda at a zoo in Scotland learned a lesson he won’t soon forget on Tuesday when the bear was shocked by an electric fence surrounding its new enclosure.

Visitors at Edinburgh Zoo were shocked themselves when they witnessed one of the United Kingdom’s two giant pandas, a male named Yang Guang, get zapped and run back to his den.

SINGAPORE SEIZES 8.8 TONS OF ELEPHANT IVORY IN RECORD $48 MILLION BUST

“You could tell he was scared because he ran off into his den,” one zoo visitor told The Scotsman. “The old enclosure had glass, but this one doesn’t. It must be to stop him from climbing out, but it’s cruel.”

But zoo officials reassured the public that the bear was only shocked once and the electric barrier will keep the animals and visitors safe. They said the pandas would learn to deal with their new environment.

“Just like farm animals, zoo animals tend to learn very quickly to avoid electric fences, which are there for their safety and to protect the public,” Royal Zoological Society of Scotland’s (RZSS) Charlotte Macdonald told the paper.

CLICK HERE FOR THE FOX NEWS APP

The panda and his partner Tian Tian were moved out of their glass-walled enclosure earlier this month, the RZSS said on its website. Their new home was supposed to offer peace and quiet away from noisy construction on a nearby former hospital.

The vulnerable species is native to China, where it is considered a national treasure.

The Associated Press contributed to this report.