BERLIN — Germany’s veteran leader, Chancellor Angela Merkel, announced on Monday that she will step down when her current term expires in 2021, kicking off a race for the top job in Europe’s biggest economy.

Although there had been widespread speculation about the end of the Merkel era, the shock announcement came after a drubbing for her conservative bloc in state elections in Hesse and Bavaria, and after months of infighting in her three-way coalition government.

Merkel, who has been chancellor for nearly 13 years, said during a news conference that she would give up the leadership of her Christian Democratic Union (CDU) at a December party congress, and will also not run again for parliament or another term as chancellor.

Describing the elections in the state of Hesse on the weekend as a “turning point,” Merkel gave a dim assessment of her government’s work so far.

“Things can’t go on like this. The image that the government is presenting is unacceptable,” she said.

“This decision is my contribution so that the coalition can focus its efforts on good governance,” she said after a meeting of her party executive in Berlin.

The decision to step down as party leader is a major U-turn for Merkel, who previously stated that the top job was inseparable from the party leadership.

Separating the two was “a gamble,” she said, adding that the risk was justifiable.

Asked by reporters if she was now a lame-duck chancellor, she replied: “This is not unusual in international politics and they govern well nonetheless.”

Three candidates have come forward to replace her as party chair, Merkel and party sources said: Jens Spahn, Germany’s current health minister and a Merkel critic; Friedrich Merz, the former head of the conservative bloc in the Bundestag; and Annegret Kramp-Karrenbauer, the CDU secretary general and one of Merkel’s allies.

On Sunday, the CDU saw its support slump more than 10 points in the state of Hesse. On Oct. 14, the CDU’s sister party, the Christian Social Union (CSU), saw a similar loss in its home state of Bavaria.

The CDU is due to elect a new leader at its party conference in December. It was previously expected that Merkel, who has chaired the party since 2000, would once again put herself forward.

Merkel’s federal-level coalition partners, the center-left Social Democrats (SPD), also suffered humiliating slumps of around 10 points in this month’s state polls, and the chancellor’s decision to give up the party leadership could increase pressure on the SPD to seek its own new leader.

Constant infighting between the coalition parties has been blamed for the poor results in Hesse and Bavaria. Current SPD chief Andrea Nahles pointed the finger at the conservatives for the government’s woes, particularly at Interior Minister Horst Seehofer, who has repeatedly sparred with Merkel over immigration policy.

Seehofer himself said that he was sorry to hear of Merkel’s decision. “It is a shame. I emphatically say: It is a shame,” he said.

“We had many discussions, but our work together was always supported by trust and mutual respect,” he said. He had worked with Merkel for the past 30 years, which was a “very, very long and productive time,” he said.

If the SPD pulls out of the coalition, it could force Merkel into a minority government or trigger a snap general election – a risky move for the ailing major parties.

The main winners in the weekend Hesse elections were the Greens, who rose 8.7 points to match the SPD with 19.8 percent voter support. The far-right Alternative for Germany (AfD) also had reason to celebrate, gaining 9 points to reach 13.1 percent and enter Hesse’s parliament for the first time.

“We should not forget that she was the first woman to lead the CDU in this place that is so often dominated by men,” Green Party co-chair Annalena Baerbock said.

Baerbock also said that Merkel led her party through a difficult time and opened it up to “a modern image of society. … And for this, we owe her respect,” she added.

The AfD’s success in Hesse means that it is now represented in all of the country’s 16 state parliaments, marking a major milestone for the 5-year-old party.