BRUSSELS — The European Union’s new agreement on migration does not obligate any country to do anything, but it appeared to be enough to save Chancellor Angela Merkel of Germany and provide a political victory to the new populist government of Italy.

Leaders of the European Union argued, cajoled and debated for nearly 10 hours until dawn on Friday to come up with a set of proposals on how to handle migration, including the idea of establishing secured centers both inside Europe and in North Africa to screen migrants, identify and distribute legitimate refugees, and keep migrants from moving from one country to another.

The leaders were not driven so much by humanitarian concerns — the levels of migration have fallen considerably — as by political necessity. In an important gesture of solidarity, Ms. Merkel’s colleagues gave her the “European answer” to her urgent domestic need — to face down a challenge to her leadership from her fellow conservatives in Bavaria and her own interior minister, Horst Seehofer.

While Mr. Seehofer said little on Friday, senior members of his Christian Social Union suggested that Ms. Merkel had obtained enough to defuse the crisis, at least for now, and preserve her ruling coalition. Hans Michelbach, a senior Bavarian legislator, said that “something moved in the right direction in Europe,” adding that his party wanted to continue to work with Ms. Merkel’s Christian Democratic Union.