The 40-year-old tried to jump the fence on Giles Street, in the Leith area of Edinburgh, at around 9pm yesterday (Tue), but managed to wedge his knee in the metals railings, leaving him about five feet from the ground.
He was spotted by a passer-by some 45 minutes later, who called emergency services and stayed with him until they arrived.
Ten fire fighters attended and took around half an hour to cut the man free.
He was taken by ambulance to the Royal Infirmary of Edinburgh with suspected “crush” injuries.
A spokeswoman for Lothian and Borders Fire and Rescue said: “We were called to the scene on Giles Street, after reports a man had got himself stuck between railings.
“He had been there for about 45 minutes before a passer-by phoned 999.
“After being freed the man was taken to the Edinburgh Royal Infirmary.
“Unfortunately the man’s predicament was not noticed for some time.
“He was no doubt in some pain and discomfort during that time.
“Fortunately, a passerby came across him and quickly summoned emergency services.
“Fire crews used specialist cutting equipment to free him as quickly as possible.”