Voters handed German Chancellor Angela Merkel's conservatives their worst-ever result in Hamburg on Sunday, punishing them for flirting with the far-right in an eastern state and descending into a messy leadership battle.
Preliminary results also showed the far-right Alternative for Germany (AfD) just scraping into the Hamburg parliament, only four days after a racist gunman killed 11 people, including himself, in the western town of Hanau.
The Social Democrats (SPD) and Greens celebrated in Germany's second-biggest city after taking first and second place, meaning they will probably keep ruling together in the northern port and city-state.
Turmoil in the federal party, as Merkel's designated successor and party leader Annegret Kramp-Karrenbauer stepped down following a scandal over cooperation in an eastern region with the far right, had been "anything but a tail wind" in Hamburg, CDU party general secretary Paul Ziemiak said.
The CDU slipped into third place, scoring just 11.2%. The AfD, which has capitalized on anger over Merkel's open-door migrant policy, especially in the former Communist East, won 5.3%, just over the 5% threshold needed to get into the state parliament, according to the preliminary results.
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 postwar 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," said CDU Secretary-General Paul Ziemiak.
The CDU leadership team meets on Monday and 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.
Merkel, chancellor for almost 15 years, has said she will not run again in the next federal election, due by October 2021.
Preliminary results put the SPD, who share power with the conservatives at the federal level, down about 6 points from the last vote in 2015 but on 39.1%, still by the far the biggest party in Hamburg.
The Greens were the biggest winners, reflecting their national strength driven by growing fears about climate change. They almost doubled their vote to 24.1% and national co-leader Robert Habeck declared it a "fantastic result."
"We have a very challenging situation for democracy in Germany, and the CDU is tied up in its own problems... It will be up to us to give the land direction and trust," Habeck told German state channel ARD.
Nationally, the Greens are second, behind the conservative bloc, and many commentators expect them to have a role in the next federal government.
With the Greens on the rise and CDU and SPD support eroding, Hamburg's results reflect the broader political picture of fragmentation visible in Germanywide polls.
But the prosperous port city with a proud left-of-center tradition could yet be the first state to boot AfD out of parliament since its founding in 2013.
In many other parts of Germany, AfD polls in double digits, scoring above 20% in several recent state elections in the former communist east.
That has been enough to throw sand in the gears of regional politics, with national repercussions.
Thuringia chaos
Earlier this month, Merkel's conservatives were shaken by the apparent alliance of their regional branch in eastern state Thuringia with AfD, voting in an FDP politician as state premier.
The breach of a historic political taboo provoked a nationwide backlash against both the mainstream right-of-center parties.
As a result, CDU leader and Merkel's heir apparent Annegret Kramp-Karrenbauer announced her resignation, throwing open the question of who will succeed the veteran chancellor following elections next year at the latest.
She is set to announce Monday how the party will select a new leader or leadership team.
Meanwhile, the SPD can breathe easy after years of ever-grimmer federal and state election results that have seen nervous party members chew through multiple leaders.
No island
While Hamburg's political makeup is unusual, events in the final week of campaigning showed that the port city is far from insulated from events in the rest of Germany and Europe.
On Friday, Swedish climate activist Greta Thunberg joined a massive "Fridays for Future" demonstration in Hamburg attended by around 10,000 people, according to police.
Weekly marches across the country by the school strike movement last year helped force Berlin to raise its climate ambitions and fix a binding end to coal power generation by 2038 in-law.
Meanwhile, both the SPD and the Greens canceled final campaign events on Thursday, after the racist terror attack in Hanau.
People from across the political spectrum have slammed AfD in the wake of the killings, highlighting similarities between its politicians' anti-migrant rhetoric and the words of the gunman in a rambling "manifesto" he is believed to have posted online.