After a lead-up marred by vocal opposition and withdrawals of support, a landmark UN-led agreement aimed at forging cooperation to manage the estimated quarter of a billion people migrating around the globe has been adopted by 164 countries at a summit in Morocco.
This month sees the adoption of two historic agreements to share responsibility for refugees and cooperate on migration.
The compacts were mandated by the New York Declaration for Refugees and Migrants, a landmark September 2016 agreement. But, more than two years later, the resulting Global Compact on Refugees and the parallel but separate Global Compact for Safe, Orderly and Regular Migration are being born into a different and more hostile political environment.
We explain what the compacts are, parse the heated political rhetoric, and speak to experts about how the agreements might improve the lives of millions of vulnerable people around the world.
At least a dozen countries pulled out of the Global Compact for Safe, Orderly and Regular Migration, which was adopted on Monday and Tuesday in Marrakech after 18 months of intergovernmental negotiations. Several others didn't attend the conference, even though a final draft was agreed by all UN member states - except the United States - in July.
The compact's critics, many of them European nations dominated by right-wing or populist parties (Hungary and Italy are among its loudest opponents), say it threatens their sovereignty and forces them to legalise illegal immigration.
But its supporters say those criticisms reflect a fundamental misunderstanding of the compact's non-binding and voluntary nature, and accuse opponents of playing to domestic audiences at a time when migration is a hot-button issue.
So what is the migration compact?
The 34-page compact is a "collective commitment" to cooperate on "all aspects of international migration". Conceived as Europe struggled to cope with the influx of more than a million refugees and migrants in 2015 and early 2016, the agreement is rooted in international human rights instruments and the 2030 Agenda for Sustainable Development. It covers some 258 million migrants worldwide, according to the UN.
In many ways, it's a milestone: many observers say it's more groundbreaking than the refugee compact in that it's the first time countries have cooperated on migration at this level. Unlike the refugee compact, which builds on the 1951 Refugee Convention, there is no comparable international framework on migration. That it was negotiated at all in the current political climate is, some say, a victory in itself.
Its 23 objectives are comprehensive and wide-ranging, addressing labour rights, use of migration detention, human trafficking, access to social services, xenophobia, recognition of skills and professional qualifications, remittances, repatriation, and climate change as a driver of displacement.
But the compact doesn't actually do much. It's basically a framework for future cooperation on migration, whatever legal form that may take: bilateral, multilateral, regional, or otherwise. Indeed, the compact commits to "ensuring that the words in this document translate into concrete actions for the benefit of millions of people in every region of the world."
Its non-binding nature means states may decide which parts to implement - or whether to implement it at all.
What were the negotiations like?
In a word: tricky. The process has been led by Louise Arbour, UN special representative of the secretary-general for international migration, along with the International Organization for Migration. Two countries, Mexico and Switzerland, have served as co-facilitators.
"Nobody got everything they wanted, but everybody got something they wanted," said Kathleen Newland, co-founder of the Migration Policy Institute, a Washington D.C.-based think tank.
During the negotiations, blocs of countries lobbied together for specific provisions. For example, African nations successfully got the addition of Objective 23 on strengthening international cooperation, which "underscor[es] the specific challenges faced in particular by African countries, least developed countries, landlocked developing countries, Small Island Developing States, and middle-income countries."
Many trade-offs centered around specific legal terms and obligations. For example, the European contingent lobbied for the promise that origin countries would readmit their own nationals who are being returned. That sparked a discussion on whether to explicitly tie the issue of non-refoulement -- the legal principle of not returning people to countries where they might be persecuted -- to migrants in the compact.
A compromise appears in Objective 21, which does not use the word non-refoulement but promises to uphold "the prohibition of collective expulsion and of returning migrants when there is a real and foreseeable risk of death, torture, and other cruel, inhuman, and degrading treatment or punishment, or other irreparable harm."
"The compromise was that we don't mention the term, but we speak to the context that the term includes," explained Pia Oberoi, the advisor on migration and human rights at the UN Office of the High Commissioner for Human Rights. "There's a lot of careful language in the compact that's not too maximalist or too minimalist. It's a delicate balance between the protection of the rights of migrants and the very strong voice of governments to retain control over their sovereign territory."
What are the criticisms?
The primary concerns relate to sovereignty. The far-right Alternative for Germany party - whose website even featured a countdown to the adoption date of what it called the "illegal" compact - claims it is a "hidden resettlement plan for economic migrants" initiated by "institutions without democratic legitimacy, such as the UN and non-governmental organisations." Germany's parliament ultimately voted to support the compact, but officials in Hungary and Italy said essentially the same thing. Other critics said it would lead to a "human right to migration".
Hungary, whose prime minister, Viktor Orbán, has made migration his signature issue, quit the compact earlier this year. But it was Austria that set off a domino effect of pull-outs across Europe when it denounced the compact in October. By the time of the Marrakech conference, Italy, Bulgaria, Poland, the Czech Republic, Poland and Latvia had all followed. Slovakia's foreign minister, Miroslav Lajcak, resigned in protest after his country's government declined to support it (though on Friday he withdrew his resignation). Belgium's government lost its majority over the prime minister's support of the compact. The Netherlands said it will support it, but only with an "explanation of position" attached to "prevent unintended legal consequences" - though legal experts have insisted that such measures are unnecessary as the compact is not legally binding anyway. Other nations that quit include Australia, Brazil, Chile, the Dominican Republic, and Israel.
The European criticisms echo what the United States said when it quit the compact last year, a move that surprised migrants' right advocates at the time.
"It sent some shockwaves through the community," recalled Marta Foresti, who directs the Overseas Development Institute's Human Mobility Initiative and served as a technical adviser on migration and development during the negotiations. "But in a strange way, it ended up being a blessing in disguise that the toughest negotiator was no longer at the table. We ended up with a stronger document."
Supporters of the compact argue that concerns about sovereignty are overblown and point to the language of the document itself where it says it "fosters international cooperation among all relevant actors on migration, acknowledging that no State can address migration alone, and upholds the sovereignty of States and their obligations under international law."
At a press conference in Geneva last month, Arbour said she was disappointed that countries were reneging on their support after participating in lengthy negotiations.
"Frankly, I am not all that concerned about what it does to the compact itself and the process," she said. "I am a little more worried about what it does to the credibility of those who, having agreed to something, and... having extracted concessions from their partners in the negotiations in that process, are now taking a different position."
What are its strengths and weaknesses?
Ironically, despite a meltdown across Europe over sovereignty threats, experts were mainly concerned about its toothlessness. The final version significantly watered the goals laid out in the New York Declaration, its founding document.
The Economist wrote last week: "As has become depressingly routine in Europe, the row over the UN compact has little to do with its ostensible target and everything to do with the smouldering embers of a culture war that the drastic reduction in illegal immigration since the surge of 2015 has failed to extinguish."
Given that political backdrop, Foresti called it a "triumph of diplomacy".
Its greatest strength is that it paints migrants as "human beings rather than profiteers," says Stephane Jacquemet, director of policy for the International Catholic Migration Commission, which helped coordinate civil society groups' input and advocacy throughout the intergovernmental negotiations.
"It's the first time you have a document from the international community to portray migration as posing, indeed challenges, but also opportunities," he said. "It's the first time you don't have anti-migration voices controlling everything and the rest of the world just reacting. There are nuances, compared to the anti-migration narrative we've seen. And for me that's the most powerful message of the global compact."
Who will it help?
At its core, the compact is meant to help UN member states manage migration, although the migrants themselves should clearly benefit from that, and experts say their human rights are protected.
Various constituencies can use the compact to their advantage.
"I think in some regions of the world - in Africa, the Middle East, Central and South America - we'll start to see more bilateral cooperation or regional cooperation on matters of cross-border migration," Foresti says. "And I think we can use the compact to push progress on particular aspects of migration. For example, campaigners who work on children's rights or migrant detention can use it as a platform to continue to hold states to account."
Stakeholders at the local level may also use the compact to create a welcoming environment for migrants even when national politics sway toward xenophobia, Foresti continued, citing last weekend's launch of the Mayors Migration Council on the sidelines of Marrakech. Businesses that have an interest in easing labour mobility might use the compact the same way.
Finally, it was the first time climate change was recognised as a driver of migration in an international forum.
"It's a big deal," says Alice Thomas, manager of the climate displacement programme at Refugees International. This opens the door for legal protections for some 140 million people the World Bank estimates will migrate due to climate change by 2050.
What happened in Marrakech?
Nations spent the first day announcing their support and their commitments to implement the compact. Tuesday was reserved for discussions on how local authorities, civil society, the public and private sector, and other stakeholders can get involved in implementation. There was also an entire week of side events.
In a speech on Monday, which prompted a standing ovation, German Chancellor Angela Merkel said illegal migration "has caused great fears in our countries... And these fears are being used by the opponents of this pact."
The UN, Merkel continued, was founded after Germany's Nazi regime brought "incredible suffering on humankind" in the Second World War, and the compact is about "nothing less than the foundation of our international cooperation."
Besides Merkel, notable attendees included the leaders of Belgium, Spain, and Denmark - and former US secretary of state Madeleine Albright, who tweeted a photo of the empty US chair.
What happens next?
The biggest test of the compact's success is implementation. It is designed to encourage cooperation at the bilateral and regional levels, and it is up to member states to make that happen.
Because fulfilling the compact's promise will cost money, it establishes a "capacity-building mechanism" whereby the UN, member states, or private donors "contribute technical, financial and human resources on a voluntary basis in order to strengthen capacities and foster multi-partner cooperation."
Then comes the follow-up stage. The compact calls for an International Migration Review Forum for member states to discuss their implementation progress at the local, national, regional, and global levels. That forum will replace the existing High-level Dialogue on International Migration and Development that takes place every fourth UN General Assembly. The compact also encourages member states to develop their own, national-level reviews.
Finally, the compact calls for the creation of a UN network on migration to be coordinated by the IOM to oversee both capacity-building and follow-up.
"The compact is a floor, not a ceiling," Thomas of Refugees International said. "If you don't implement words on a paper, they're just words on a paper. Marrakech is a first step."