Voters handed Angela Merkel's conservatives their worst result in Hamburg on Sunday, punishing them for flirting with the far-right in an eastern state and sparking a leadership fight.
Projected results also showed that the far-right Alternative for Germany would be ejected from the Hamburg Parliament four days after a racist gunman killed 11 people, including himself, in the western town of Hanau.
It would be the first time the party, which has capitalised on anger over Mrs Merkel's open-door migrant policy, especially in the former Communist east, was kicked out of a state assembly.
"Nazis out," chanted supporters of the victorious Social Democrats (SPD) and Greens as they celebrated in Germany's second-biggest city.
The two are set to continue ruling together in the northern city-state.
The conservative Christian Democrats (CDU) suffered after party leader and Mrs Merkel's protegee, Annegret Kramp-Karrenbauer, said she would stand aside, blowing open the race to succeed the chancellor and throwing the party into turmoil.
The CDU slipped into third place, scoring 11.3 per cent. The AfD was in last place on 4.7 per cent, short of the 5 per cent threshold needed to get into the state parliament.
Ms Kramp-Karrenbauer's move came after an eastern branch of the CDU defied the national party and voted with the AfD to install a state premier from a third party, breaking a post-war consensus among established parties of shunning the far-right.
"It is a bitter day for the CDU in Germany and a historically bad result in Hamburg," party secretary general Paul Ziemiak said.
The CDU leadership team meets on Monday and Ms Kramp-Karrenbauer is expected to set out a timetable for a decision on the party chair and possibly the chancellor candidate.
Four or five candidates are jockeying for the jobs.
Mrs Merkel, chancellor for almost 15 years, has said she will not run again in the next election, due by October 2021.
Preliminary results from public broadcaster ZDF put the SPD, which shares power with the conservatives at the federal level, down about 7 points from the last vote in 2015 but on 37.8 per cent, still by far the biggest party.
The Greens were the biggest winners, reflecting their national strength driven by growing fears about climate change.
They roughly doubled their vote to 25.4 per cent and national co-leader Robert Habeck declared it a "fantastic result".
Nationally, the Greens are second, behind the conservative bloc, and many commentators expect them to have a role in the next federal government.

