Chanting "Down, Down USA, Libya, Libya," and carrying banners and the national flag of Gaddafi's Libya the protesters surged towards Ban and his 15-strong delegation that included a UN deputy secretary general and former Chilean president Michelle Bachelet, the head of UN women.
The UN chief had been following in the footsteps of a string of international visitors to Cairo in recent weeks, including US Secretary of State Hillary Clinton, in touring the square which was the focus of mass protests that forced veteran president Hosni Mubarak from power last month.
Police and troops intervened to let the UN group make good their escape.
He was unhurt after the incident, the AFP correspondent said.
On Sunday, Gaddafi loyalists accompanied by two regime envoys had attempted to occupy the rebel-controlled mission to the Arab League but had been evicted by troops, who closed down the mission.