A male baboon on his way to a vasectomy escaped his transport with his two female companions and ran amok on the Royal Prince Alfred Hospital campus on Tuesday afternoon.

NSW Health Minister Brad Hazzard said the trio were arriving at the facility when a lock on the door of their vehicle failed.

"Last I heard they'd had a good look around the precinct and ended up in the car park where they were behaving far better than what we’d expect of baboons," he said.

"They obviously decided that inspecting the premises was an appropriate way to spend a couple of hours at the hospital."