Police gained the upper hand in Hamburg early on Saturday morning after a day of running clashes with anti-capitalist protesters seeking to disrupt the city's G20 summit of global leaders.

Heavily armed police commandos moved in after activists had spent much of the day attempting to wrest control of the streets from more than 15,000 police, setting fires, looting and building barricades.

With meetings between leaders of the club of 20 largest global economies finished for the day, police stormed the last holdouts, who had gathered in the Schanzenviertel district, an area known for its left-wing activism and culture of squatting.

With two months to go before she seeks re-election, Chancellor Angela Merkel had hoped to cement Germany's growing global leadership role with a demonstration of its unwavering commitment to free speech, assembly and dissent by holding the summit in the centre of a city with a proud radical tradition.

Protesters torched cars and lorries, smashed windows in banks, looted retail stores and hurled paving slabs and other objects before police managed to restore order. Some 197 officers were injured after two days of clashes in the port city. Police made 19 arrests and detained dozens more.

Standing in a nearby falafel restaurant, Mohammad Halabi, 32, a Syrian who arrived in Germany as a refugee some 18 months before, surveyed the scene with disbelief.

"They are crazy. I can't believe my eyes," he said. "They have such a beautiful country and they're destroying it."

But G20 participants said they had never seen protesters closer to such a summit than in Hamburg and praised the work of police in keeping the event safe, suggesting Merkel's gamble had paid off.

BEETHOVEN VS HENDRIX

"I have every understanding for peaceful demonstrations but violent demonstrations put human lives in danger," Merkel had said earlier.

Most of the 100,000 protesters were peaceful, hoisting signs saying the G20 leaders were not welcome, or engaging in mass bicycle processions through the city centre wearing brightly coloured uniforms.

When world leaders including U.S. President Donald Trump and China's President Xi Jinping gathered for a Beethoven concert in the Elbphilharmonie concert hall on one side of the river, protesters blared the music of Jimi Hendrix from the other side.

But in the night's most dramatic scenes, police pursued members of the radical Black Bloc movement, which wants to overthrow capitalism, across scaffolding as they sought refuge on rooftops. Below, burning barricades billowed thick smoke.

Despite the chaos that threatened to overwhelm parts of the city during much of the day, the summit, with thousands of participants from dozens of countries, was largely unaffected.

Police declined to clear U.S. first lady Melania Trump's motorcade to leave her hotel for a tour of the historic harbour, and protests delayed buses taking visitors away from the state dinner that concluded the meetings.

The summit is due to conclude on Saturday.