Campaigners congregated in the city’s Nicolson Square from about 7pm on Thursday after news of the action spread across social media.
Vehicles that appeared to be from the Home Office were spotted in the area earlier in the day.
The Home Office said Immigration Enforcement attended an address in Potterrow in a pre-planned and intelligence-led operation.
It said two people were found to be in breach of immigration laws and were placed on immigration bail.
A Home Office spokeswoman said: “It is unacceptable for people to attempt to block legitimate actions of law enforcement as they work to remove those with no right to live or work in the UK.
“Through our Nationality and Borders Act we are taking steps to fix the broken system to make it fair to those in genuine need and firm on those who seek to abuse it.
“An operation was carried out in Edinburgh on Thursday and to suggest that protesters had an impact on the outcome is wrong.”
The Home Office said the appropriate legal protocol was followed and Police Scotland were notified about the operation in advance, as is routine.
Onlookers said the scene in Edinburgh was similar to action that took place on Kenmure Street in Glasgow last year when hundreds of people surrounded an immigration removal van in a bid to stop the detention of two Indian nationals, Sumit Sehdev and Lakhvir Singh.
Shortly before 8.30pm on Thursday , the crowd cheered as the immigration team left the building, having earlier agreed to de-arrest those inside.
Among the crowd was a bagpiper playing Scottish songs; sending a message that he believes everyone is welcome in his country.
Others chanted ‘this is what democracy looks like’ and ‘people united, we’ll never be divided’.
One man, who was in floods of tears, was comforted and hugged by emotional protestors.
In a statement on Thursday, Police Scotland said: “Around 6.45pm on Thursday May 5, police were called to an address on Potterrow, Edinburgh, following reports of a large protest outside a property.”