Throngs of people urged him to jump from the 23rd floor of the Cape Town Civic Centre.
The man tied a rope around his waist, dangled perilously from the edge of the building and urinated in full view of the public.
Police cordoned off streets leading to the civic centre and emergency services were on stand-by.
He gesticulated frantically as he spoke to negotiators trying to lure him off the building and almost fell off after a production company flew a drone with a mounted camera towards him.
Police arrested the crew.
The man’s antics also sparked a online frenzy after a video of the drama was posted on YouTube.
City employees noticed him shortly after 8am.
Wilfred Solomons-Johannes, spokesman for the city’s disaster risk management team, said the man had been persuaded to come to safety before 5pm.
“The hostage negotiation team is now dealing with the matter.
“The man has been taken off the building,” said Solomons-Johannes.
“It is a hostage matter, police are dealing with it.”
Western Cape police spokesman Lieutenant-Colonel André Traut said the man had been handed over to the department of health.