HAMBURG—Riots that raged for hours just a mile from the Group of 20 meeting site left German officials struggling to explain over the weekend how protests that had long been predicted spiraled out of control.

Only after SWAT teams, riot police and water cannons swept block by block were authorities able to end the riots early Saturday morning in the left-leaning Schanzenviertel neighborhood, a 20-minute walk from the venue where leaders of the world’s 20 largest economies met.

...