About 650 people gathered at Hamburg's main train station on Saturday afternoon to dispute Germany's speeding up of migrant deportations.
The protest group, which included refugees from Sudan, Afghanistan, Syria and Eritrea, called for the changes to migrant policy to be rolled back.
The German government has quickened the time taken to eject failed asylum seekers in the wake of the deadly Berlin Christmas market attack, carried out by a Tunisian migrant who was due to be sent home.
Angry at the changes, many demonstrators chanted and held banners that read: "stop the deportations" and "no human is illegal."
The protesters picked the northern German city as it will be the venue for next month's G20 summit of leaders from the world's biggest economies.
Read more: Police, demonstrators prepare for G20 summit in Hamburg
Public broadcaster NDR said police had deployed several hundred uniformed officers to accompany the demonstrators.
Detention plans criticized
Later on Saturday, around 400 people rallied in the southern Harburg district of the city where police have built a temporary detention center to house any protesters arrested during the summit of world leaders scheduled for July 7 and 8.
The 11,000-square-meter (18,500-square foot) center has 70 group cells and 50 single cells that can hold as many as 400 detainees.
Another protest group rallied later on Saturday demanding that they be allowed to set up a large protest camp site during the summit.
On Friday, a regional court ruled against what demonstrators said was their legal right to erect 3,000 tents at a Hamburg public park. Their plans had previously been rejected by city officials.
Protesters to appeal
"On this matter, we will now lodge a complaint with the Federal Constitutional Court and we hope for a quick verdict," the German news agency dpa cited the anti-capitalist camps group as saying.
The local Green Party has promised to help protesters find a suitable location, subject to proper organization, safety, and hygiene rules being respected.
Read more: Merkel warns against protectionism ahead of G20 summit
Authorities are expecting up to 10,000 demonstrators during the two-day G20 talks, which will be attended by US President Donald Trump, German Chancellor Angela Merkel and French President Emmanuel Macron, among other world leaders and heads of state.
Several other protests are expected in the coming days, authorities said.
mm/jm (dpa, NDR)