BERLIN — Chancellor Angela Merkel has agreed to limit the number of asylum seekers allowed to enter Germany each year to 200,000, a concession to her Bavarian partners as she tries to form a government after losing seats to the far right in elections last month.

Ms. Merkel angered many German voters with her willingness in 2015 to let in anyone who could reach the country, which resulted in the arrival of more than a million people. Some voters responded by propelling the far-right party Alternative for Germany — known by its German initials, AfD — into Parliament last month, with support coming from people who had previously stayed home and from Ms. Merkel’s conservative bloc, especially its Bavarian branch, the Christian Social Union.

After hours of talks on Sunday that dragged into the night, Ms. Merkel’s Christian Democratic Union and the Christian Social Union also agreed to provisions allowing the 200,000 limit to fluctuate depending on circumstances.

Horst Seehofer, leader of the Bavarian party, had been demanding for months that a limit be set on the number of people allowed to apply for asylum in Germany. The chancellor refused to yield to his demands, until he made the issue a condition for helping her form a new coalition.