AfD's slogan "let's complete the change" harked back to the 1989 "Wende" (change), which many eastern Germans see as unfinished business. Despite huge investment from the richer west, for many people the economic restructuring did not transform their lives as they had hoped.

"We're satisfied in Brandenburg as well as in Saxony," AfD co-leader Alexander Gauland said, adding that his party had "punished" Mrs Merkel's conservatives.

But despite the gains, the result may disappoint AfD as the party had hoped to come top in Brandenburg, the BBC's Damien McGuinness reports from Berlin.

The CDU state premier of Saxony, Michael Kretschmer, said "I'm very happy with the result", but added that opposition messages had made an impact on social media. "The filter bubble on the internet is so powerful, and in 20 months you cannot reach everyone," he told broadcaster ARD.

The CDU-SPD national coalition is due to last until federal elections in 2021, and a collapse could trigger a snap election or result in a minority government.

Mrs Merkel herself plans to step down as chancellor in 2021, having already resigned as CDU leader at the end of last year.