text: The right-wing AfD party, formed only three years ago, came second in the chancellor's home state of Mecklenburg-West Pomerania, polling 21%.
  Mrs Merkel has defended her policies but said she needs to "win back trust".
  Some 1.1 million refugees and migrants entered Germany in 2015.
  Many of them arrived after the government decided to loosen border controls just over a year ago.
  Mrs Merkel, who is in China for the G20 summit, said she was "very unhappy" with the election result.
  "Everyone now needs to think about how we can win back trust - most of all, of course, myself," she said.
  "Obviously it [the election result] has something to do with the refugee question. But I nevertheless believe the decisions made were right and we have to continue to work on them."
  This is humiliating for Angela Merkel - not least because this was on home turf.  This election - which was seen as a significant test ahead of next year's general election - was all about her refugee policy. For a year she's insisted "Wir schaffen es" (we can do it) but German voters aren't convinced.
  Alternative fuer Deutschland's anti immigrant and increasingly strident anti-Islam message has a powerful appeal to people concerned about integration and worried about domestic security.
  It doesn't look good for Mrs Merkel. Her approval ratings are at a five-year low. But don't be tempted to write her off just yet - she has a habit of bouncing back and there is no serious contender waiting in the wings to replace her.
  The AfD leader in Mecklenburg-West Pomerania, Leif-Erik Holm, suggested that "perhaps this is the beginning of the end of Angela Merkel's chancellorship".
  AfD (Alternative fuer Deutschland) now has delegates in nine of Germany's 16 states.
  "It's a debacle for Angela Merkel and her refugee policy," said Edmund Stoiber, honorary chairman of the Bavarian-based CSU, the sister party of the CDU.
  It was not enough to criticise the AfD's voters, he argued - the CDU had to understand why people were losing faith in its policies.
  Mr Stoiber called for a limit on the number of people entering Germany.
  The CDU is in coalition nationally with the SPD, and also regionally in Mecklenburg-West Pomerania, although that may now change.
  Wolfgang Bosbach of the CDU said the arrival of hundreds of thousands of migrants without documents had "put the wind in AfD's sails".
  CSU Secretary General Andreas Scheuer spelt out that what was now needed was a cap on refugee numbers and better repatriation of failed asylum seekers.
  Ahead of the vote Mrs Merkel gave a defiant interview on immigration, insisting that change was not a bad thing and that "Germany will remain Germany, with everything that is dear to us".
  Although the chancellor's popularity has fallen nationally, she still has 45% approval ratings and has yet to decide if she wants to run for a fourth term in the September 2017 elections.
  "How many more electoral disasters can Merkel take?" wonders tabloid Bild, predicting that opposition to the chancellor inside her conservative bloc could erupt with full force.
  A piece in the Sueddeutsche Zeitung predicts an "autumn of discontent" for the chancellor, while Die Welt thinks many of her long-standing critics will now "break cover" and "let rip".
  Der Spiegel believes while the election is a "debacle" for Mrs Merkel, her job is not on the line quite yet.  And Frankfurter Allgemeine Zeitung argues that voters are angry at "(almost) all" mainstream parties, and not just the Christian Democrats, mainly over globalisation and "compromise-based politics".
  What does Germany's right-wing AfD want?
  Frauke Petry: Profile of AfD leader
target: German Chancellor Angela Merkel's allies have urged her to change course on refugees after her governing CDU party was beaten in a regional election by an anti-immigrant party.