Mr Farage arranged a press conference in the Canons' Gait pub on Edinburgh's Royal Mile, near the Scottish Parliament, to promote his candidate Otto Inglis in the Aberdeen Donside by-election.
The pub was soon filled by dozens of protesters shouting "racist Nazi scum".
Protester Max Crema, 21, an economics student and vice president of services at Edinburgh University Students Association, suggested UKIP has "a well documented history of racism".
Mr Farage replied: "If you believe that then you are less intelligent than you look, dear boy.
"We are a non-racist, non-sectarian party and unlike every other party in British politics we actually forbid people who have been on extreme left or right-wing extremes from joining our party.
"The Labour Party actually has former BNP members sitting as Labour councillors, so don't give me that rubbish."
Bar staff were forced to clear the pub as the protesters became increasingly rowdy.
The Ukip leader attempted to make an escape by taxi but protesters blocked its path.
Taxi driver Alexander McMillan said he was shaken by the incident.
"They were all going bloody mental," he said.
"I couldn't take him, they were attacking that taxi and blocking its path so I just had to give up, and then the police got involved."
Police eventually escorted Mr Farage back into the pub and barricaded the doors against protesters, and a police van was dispatched to take him away.
Protesters chanted "Farage is being lifted" and "How does it feel to be treated like an asylum seeker?"
Mr Farage later told ITV News: "It was pretty threatening. This is not a great place to be, I thought to myself. But I have been in lots of worse places."