BERLIN — Chancellor Angela Merkel’s conservative bloc won a lackluster victory in Germany’s national election Sunday while the anti-migrant, nationalist Alternative for Germany party managed a triumphant entry into parliament.

Merkel’s main center-left rivals, the Social Democrats, slid to their worst result since World War II, projections showed.

The party, led by Merkel’s challenger Martin Schulz, vowed immediately to leave her coalition government and go into opposition.

The outcome puts Merkel on course for a fourth term as chancellor – but means that she likely faces the tricky task of forming a coalition government with two new partners. Merkel acknowledged that it would take time, but said that “we live in stormy times” and other parties should show responsibility.

“I have the intention of achieving a stable government in Germany, and that has been a hallmark” of the country, she said.

Projections by ARD and ZDF public television, based on exit polls and partial counting, showed Merkel’s Christian Democratic Union and their Bavaria-only allies, the Christian Social Union, winning around 33 percent of the vote – down from 41.5 percent four years ago. It was one of their weakest postwar showings.

Schulz’s Social Democrats were trailing far behind, with just under 21 percent support. That would be the outright worst postwar result for the party, which has served since 2013 as the junior partner in a “grand coalition” of Germany’s biggest parties under Merkel.

Merkel was greeted at her party’s headquarters by supporters applauding and chanting “Angie!”

“Of course, we would have preferred a better result, that is completely clear,” she said. “But we mustn’t forget that we have had an extremely challenging parliamentary term behind us.”

“We have a mandate to form a new government, and no government can be formed against us,” Merkel said.

“We want to win back AfD voters by solving problems, by taking account of their concerns and fears, and above all with good policies,” Merkel said.

Smaller parties were the chief beneficiaries of the erosion in support for Germany’s traditionally dominant parties – above all the right-wing Alternative for Germany, or AfD, whose support was just over 13 percent.

AfD capitalized on discontent with established politicians but particularly targeted those angry over the influx of more than 1 million mostly Muslim migrants into Germany in the past two years under Merkel.

AfD co-leader Alexander Gauland vowed that “we will take our country back” and promised to “chase” Merkel.

“This is a big day in our party’s history. We have entered the Bundestag and we will change this country,” Gauland said.

Big cheers went up at AfD’s election party after exit polls showed them finishing in third place.

Some supporters chanted “AfD! AfD!” and others started singing the German national anthem.

Outsides, hundreds of anti-AfD protesters shouted “all Berlin hates the AfD,” “Nazi pigs,” and other slogans, while several protesters threw bottles as police kept them away from the building.

Only subscribers are eligible to post comments. Please subscribe or to participate in the conversation. Here’s why.

Use the form below to reset your password. When you've submitted your account email, we will send an email with a reset code.