When he later left the Canons' Gait pub in Edinburgh's historic old town and was escorted into a police van, protestors chanted "scum, scum, scum".
Mr Farage was in Edinburgh to launch his party's Scottish campaign following recent electoral gains in England.
Police said two men had been arrested following the protest.
Mr Farage told the BBC he had never had a reaction like this before.
Earlier this week, Mr Farage said First Minister Alex Salmond was "illogical" to want to keep an independent Scotland in the EU.
During the protest, Max Crema, 21, 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."
Protesters chanted "Farage is being lifted" and "How does it feel to be treated like an asylum seeker?"
A UKIP spokesman described the scene as "inchoate rage".
"Was it anti-English? I doubt it, I don't think they thought that far," he said.
"I don't think he was shaken up by it. He was laughing, in fact."
A Police Scotland spokeswoman said: "Two men have been arrested following a protest outside a public house on Edinburgh's Canongate.
"Officers responded to the address to facilitate a peaceful demonstration which arose during a UKIP meeting that was taking place inside.
"During the protest, which took place around 4.30pm, a 49-year-old man was escorted from the premises to ensure his safety."
UKIP leader Nigel Farage had to find refuge in a pub after he was swarmed by angry protesters as he left a press conference.