Angela Merkel's ruling CDU party has been beaten into third place by the anti-migrant Alternative für Deutschland (AfD), following elections in a German state.

The right-wing populist AfD won 20.8 per cent of votes in the election for the state legislature in Mecklenburg-Western Pomerania. Ms Merkel's Christian Democrats polled 19 per cent, their worst result yet in the state.

The centre-left Social Democrats, who led the outgoing state government in a coalition with the conservatives, remained the strongest party with 30.6 per cent of the vote.

Mecklenburg-Western Pomerania, in Germany's northeastern corner, is home to 1.6 million of the country's 80 million people and is a relative political lightweight. It is, however, the state where Ms Merkel has her parliamentary constituency, and Sunday's regional vote was the first of five before a national election expected next September.

Chancellor Merkel's refugee policies were a prominent issue in the campaign for Sunday's election, which came a year after she decided to let in migrants from Hungary. Germany registered more than 1 million people as asylum-seekers last year.

Ms Merkel has stuck to her insistence that “we will manage” the refugee crisis, and has also said that “sometimes you have to endure such controversies.”

National AfD leader Frauke Petry celebrated “a blow to Angela Merkel.” Local AfD leader Leif-Erik Holm told supporters: "Perhaps this is the beginning of the end of Angela Merkel's chancellorship today."

The AfD, however, fell well short of its aim of becoming the strongest party, and also didn't match the 24.3 per cent support it won in another eastern state, Saxony-Anhalt, in March.

Earlier in the year, the centre-right CDU party was expected to help form the region's coalition government along with the centre-left Social Democratic Party (SDP) mirroring the arrangement at the federal level.

Frozen cake thrown at right wing politician in Germany

“This result, and the strong performance of AfD, is bitter for many, for everyone in our party,” said Peter Tauber, Ms Merkel's Christian Democrats' general secretary.

He said the state government's positive record took a back seat for many voters, “because among a recognisable part, there was an explicit wish to voice displeasure and protest, and we saw that particularly strongly in the discussion about refugees.”

Sunday's result could make it more difficult for Ms Merkel to bury a festering dispute with the Christian Social Union, the Bavarian arm of her conservative bloc, which has long criticized her decision to open the borders and advocated an annual cap on migrants.

CSU general secretary Andreas Scheuer said that “we feel vindicated in our course.”

The AfD is now represented in nine of Germany's 16 state legislatures and hopes to enter the national Parliament next year. There's no realistic prospect at present of the AfD going into government as other parties will not deal with it.