The defendant, who was not named by the court in the northern port city, received a custodial sentence of two years and seven months for throwing two bottles at police, DPA news agency said.
He was convicted of "aggravated disturbance of the peace, grievous bodily harm, a serious attack on a security officer and resisting arrest" on July 6th, the eve of the summit.
The sentence went beyond the demand of one year and nine months from prosecutors. The defence had called for an acquittal.
An audience of around 40 people in the courtroom expressed shock over the relatively severe sentence.
Hamburg police said on Monday they have opened more than 2,000 criminal probes related to the anti-G20 violence.
The global summit that brought together US President Donald Trump, Russia's Vladimir Putin, China's Xi Jinping and other leaders was marred by mass protests, sit-in blockades and street clashes where anarchist mobs battled riot police, torched cars and looted shops.
The violence proved embarrassing for host Chancellor Angela Merkel as well as local officials, prompting calls for Hamburg Mayor Olaf Schulz to resign.
Last week Germany's interior ministry banned the country's main online platform for far-left activists and militants due to alleged links with the G20 rioting and other offences.
The site, linksunten-indymedia.org, has allowed anonymous users to organize demonstrations and blockades but also to celebrate violence against police or to share instructions on making Molotov cocktails.