The trains from Copenhagen to Malmö leave every few minutes. Shortly after departing the Copenhagen airport they reach the Øresund Bridge, a low-lying metal structure that spans the strait connecting Denmark and Sweden. They pass a watery wind farm, its modern turbines rotating in the breeze, and then, about five minutes later, reach Malmö, the largest city in the Skåne region of Sweden. It’s a pretty, albeit anticlimactic, journey between two countries.

The Øresund Bridge opened to great fanfare in July 2000, replacing what had been a convenient, if slightly slow, ferry route. Copenhagen–Malmö was well on its way to becoming a truly binational—perhaps even post-national—metropolis. Proponents saw it as further evidence that borderless travel was a permanent fixture within the European Union, the urban manifestation of the dream of an increasingly unified, integrated continent.

In many ways, that dream was born in this very region. Open borders within Scandinavia began only a decade after the Second World War, preceding the Schengen Agreement (which abolished internal passport controls among signatory nations) by four decades. By 2015, almost all EU countries, as well as a handful of nonmember states, were part of the agreement. As a traveler or resident, once you were in, you were in. And until you left, you didn’t have to show your passport.

Yet in early January 2016, in the face of an unprecedented flow of economic migrants, political refugees, and asylum seekers from the Middle East, North Africa, and Asia, the Social Democratic government of Sweden unilaterally, and with almost no notice, imposed border controls over the Øresund Bridge. Swedish officials did so not because they had suddenly adopted an anti- immigrant stance, but because so many other EU nations had made it clear they were determined not to welcome refugees. This shift had made Sweden and Germany, the two countries with the most liberal approach on the issue, an irresistible magnet for hundreds of thousands of desperate migrants. Commuters now had to show a passport before boarding the train at the Copenhagen airport. On some days, they had to disembark at the first station on the Swedish side and show their passports again. What had been an easy half-hour commute now became an exercise in inconvenience. On some days, the process could add an extra hour to the journey.

This is the story of a dream’s implosion—and the turbulent politics behind that implosion—as Europe failed to come up with a common, continent-wide response to the refugee crisis of the past few years, and as individual countries were left to navigate these waters as best they could. The consequences may not be as dramatic as those following the landmark Brexit vote this past summer, but like Brexit they are hugely significant, calling into question the long-term future of the European Union.

* * *

Forty thousand refugees crossed the Mediterranean in 2013. A year later, that number was 200,000. The following year, it reached a staggering 1 million—and this is just a fraction of the asylum seekers who entered the EU through all possible routes. Among them was 17-year-old Ahmed, who didn’t want his last name used because his parents still live in a neighborhood in Aleppo, Syria, that has repeatedly changed hands between Assad’s forces and ISIS. “Daesh,” as he calls the group, is “the worst”: “They kill anybody. They can kill you if you smoke, cut your hair the wrong way. They can kill you for one word.”

Ahmed arrived in Sweden in October 2015. It was the end of a 23-day odyssey that had begun with a surreptitious departure from Aleppo. He left with a few thousand dollars in cash, which his parents had managed to set aside for his journey. That money was his lifeline as he made his way to safety—first to the Turkish border; then by boat to Greece; and then through a combination of transport methods as he crossed the Balkans, Austria, Germany, Denmark, and finally the Øresund Bridge.

Two of Ahmed’s second cousins, 15-year-old Khalid and 16-year-old Nabil, also came to Sweden in the fall of 2015, traveling on separate boats and in separate convoys. Nabil, who is the tallest of the three, wears a blue jacket over a blue shirt. His hair is cut short; his facial expression is serious. Like Khalid, he fled the bloodshed and chaos in ISIS’s capital, the Syrian city of Raqqa. “The situation there is not good,” Nabil recalls drily. “We saw many dead people in the streets. Many dead people. Beheaded.” Often, he says, airplanes would fly in and start firing at the people in the streets below.

Khalid has similar stories. A quiet boy with thick hair and newly grown sideburns—a child, really—he recounts the extraordinary calculus that determines the fate of these refugees. Even though he could hardly swim, he didn’t hesitate to make the dangerous sea crossing to seek safety in Europe. “If we didn’t risk getting killed at sea, we’d be killed in Syria,” he says.

Like the tens of thousands of refugees who crossed the Øresund Bridge into Sweden last year, the three boys were welcomed by a coalition of humanitarian groups, local mosques, volunteer lawyers, and an organization called Refugees Welcome Sweden. The art cooperative Kontrapunkt, for example, runs seven centers in Malmö, and set up soup kitchens, medical clinics, temporary bunk beds, and cultural events for the new arrivals. Some groups helped them find housing and liaise with the Swedish authorities; others provided transportation northward, to the major cities of Göteborg and Stockholm. Legally, these groups are on safe ground if they provide transport within the country, but they can be arrested for transporting migrants to the border so that they can continue on to Norway or Finland.

In October 2015, the high-water mark for the EU refugee flow, roughly 40,000 people sought refuge in Sweden—which has a total population of only 10 million. That would be the equivalent of 1.2 million people seeking refuge in the United States in one month. Over the course of 2015, 163,000 refugees entered Sweden and were officially registered as asylum seekers (though only one-fifth were ultimately granted asylum). Again, as a proportion of the total population, this is the equivalent of more than 5 million men, women, and children arriving in the United States in a single year. The number was nearly double the previous record high for Sweden, set in the early 1990s at the height of the wars that followed the disintegration of Yugoslavia. Whatever your politics, these are huge numbers, almost guaranteed to create a backlash.

* * *

Sweden’s Danish neighbors are solidly, if somewhat skeptically, pro–European Union. Although Danes have voted against closer EU integration three times in the past 20 years, polls show that nearly three-quarters think their future will be better inside the EU than outside it. But they have also been less comfortable with high levels of immigration. In contrast to Sweden, a succession of Danish governments attempted to clamp down on non-EU migration for several years prior to the recent influx of refugees. They tended to view Sweden’s open-door policy as naive, if not stifling. It wasn’t that Swedes were more liberal, they thought; rather, the opinion-making class had created a harmful narrative around migration by labeling anyone who questioned it an extremist. And this had become self-fulfilling, pushing more and more ordinary Swedes toward genuinely extremist political organizations operating outside of the country’s democratic structures.

Over the previous 20 years, both Social Democratic and Liberal governments in Denmark became increasingly tough on non-EU immigrants. New legislation made it harder for them to qualify for residency rights and more difficult to bring over family members. Access to the country’s generous social benefits was restricted, and rigorous language and cultural tests for those seeking citizenship were introduced.

Denmark is a historically Protestant nation, which, unlike the United States, has no separation of church and state. “We have been a very homogeneous society for many years,” explains Bjarke Møller of the Copenhagen-based Think Tank Europa. “The cultural component” of mass migration is “explosive,” he adds. “It feeds into the question of the unity of the state and religion. The Protestant nation-state is having trouble handling other religions.”

Once the refugee crisis hit, Danish opposition to immigration morphed into a general reluctance to accept large numbers of refugees. The government began taking out ads in Middle Eastern newspapers warning would-be migrants that they weren’t welcome. Legislators passed an asset-forfeiture law that allows the government to seize the valuables of refugees entering the country. They rushed a set of 39 amendments to the country’s Aliens Act through the Danish Parliament. And in November 2015, the government introduced legislation making it possible to suspend a detained asylum seeker’s right to see a judge within 72 hours. Taken together, these new laws and policies locked into place a new, more punitive approach to migration. “It wasn’t an official state of emergency, but it was a de facto state of emergency,” recalls Louise Holck, deputy executive director of the Danish Institute for Human Rights.

The reforms put Denmark at odds with several articles in the European Convention on Human Rights, a treaty signed by 47 countries, which is increasingly unpopular with conservatives across Europe. The Danish government stated that it was prepared to defend itself if a case was brought against the country at the European Court of Human Rights, in Strasbourg, France. (In May, the court found that Danish immigration laws on family reunion were discriminatory.)

The populist Danish People’s Party was at least partly responsible for pushing the country down this road. In 2011, the party’s message—which combined strong support for Denmark’s generous welfare state with calls to drastically curtail immigration, especially of Muslims—resonated with more than 12 percent of the electorate. By 2015, the DPP had become the largest conservative parliamentary bloc, capturing 21 percent of the vote; in fact, it had more MPs than did the governing Venstre (Liberal) Party. Venstre leaned heavily on the DPP for support, and the Social Democrats also courted its mainly working-class voters.

“I used to be a socialist. To me, it’s weird being described as a right-winger,” explains Søren Espersen, a onetime journalist who is now the DPP’s immigration spokesperson in Parliament. Espersen lives in an 18th-century thatched-roof house in Lundby, a village 100 kilometers south of Copenhagen. Middle-aged and clean-shaven, he’s dressed casually in jeans, a blue V-neck sweater, and sandals. Pondering how his country has changed, Espersen speaks in a gentle tone about what he sees as a calmer, rosier prelapsarian past, before Denmark’s sovereignty was compromised by EU-wide regulations and mass migration. “I want the Danish Parliament to be the law, the Danish high court to be the highest court,” he says, using language reminiscent of Conservative Brexiteers, with whom his party’s representatives caucus in the European Parliament. “We can make our own rules and regulations; we have been an independent country for 1,000 years.”

Echoing concerns voiced by socially conservative parties throughout Europe and the United States, Espersen says he fears the influx of Muslims who, he argues, have no desire to integrate into the country or to participate in its democratic institutions. “The reluctance they show to Danish traditions and culture is appalling. Why would you want to go to a new place and change it to the place you left?” Responding to these perceived threats, the DPP has advocated withdrawing from parts of the European Convention on Human Rights, which would allow Denmark to massively curtail the number of refugees and send them back once their countries stabilize. Espersen would also like to declare a two-year moratorium on all new immigration from Muslim-majority countries, though he does not envision banning Muslim visitors (indeed, he considers Donald Trump’s proposal to deny all Muslims entry to the United States too extreme).

Instead of ostracizing the DPP, Denmark’s mainstream parties have attempted to co-opt it. The strategy “has led to a more moderate and realistic approach,” says Marcus Knuth, Venstre’s immigration spokesperson. “We want Denmark to be as open as possible for people who come here legally, and shut as much as possible for people who come here illegally and don’t want to work and be part of society. My hope is we can keep the amount of illegal immigration and asylum-seeking to a minimum.”

* * *

Swedish opinion-makers initially turned up their noses at their Danish neighbors, who they believed were taking a dark turn toward xenophobia. Although polls showed that 15 percent of voters supported the far-right Sweden Democrats in 2015, the country’s government was headed by the center-left Social Democrats, and all of the mainstream parties had agreed to ostracize the extremist fringe.

Below the surface, however, a roiling cauldron of anti-immigrant sentiment was being stoked, which the Sweden Democrats and an array of even more extreme (and overtly violent) neo-Nazi groups were in a prime position to exploit. As immigration rose relentlessly through 2015, so too did support for the far right. By the end of the year, roughly one in five voters were expressing support for the Sweden Democrats, and as reports of crimes carried out by Muslim immigrants spread, so too did reports of anti-immigrant violence perpetrated by fascist gangs.

Sweden’s policy “created a huge strain on the institutions that take care of refugees and treat their asylum applications,” says Nils Holtug, director of the Centre for Advanced Migration Studies at the University of Copenhagen. “It was difficult to find accommodation for refugees, and there were worries about the financial burdens on the state—and, for some people, worries about the cultural impact of such a large influx.”

In the face of rising crime rates, a multibillion-dollar strain on the country’s welfare system, and housing shortages in areas where large numbers of refugees were being resettled, Sweden’s government began walking back its open-door policy toward refugees in late 2015. Despite opposition from the Greens, the junior party in the governing coalition, and in an attempt to head off rising support for the far right, the government adopted policies that were more in line with public preferences, limiting family-reunification rights and restricting access to the welfare system for asylum seekers facing deportation orders.

After decades of welcoming refugees without restriction, Scandinavia saw a new consensus emerging: Fewer refugees would be admitted in the first place, and those who were would have limited access to the state’s social benefits.

* * *

The Dublin Convention is a series of regulations that provides a humanitarian framework for the EU’s treatment of refugees and that stipulates national responsibilities within the union; it assigns responsibility for refugees to the first member state that receives them­. The convention was signed by the core group of EU nations in 1990 and later expanded to include every EU member but Denmark in 2003 (the latter finally joined in 2006). In theory, Italy and Greece had to absorb the bulk of the migrants who crossed the Mediterranean in 2014 and ’15. In practice, however, hundreds of thousands quickly headed north; Greek and Italian officials either processed the migrants before sending them on their way or didn’t even bother to stop them for processing.

On trains and buses, in cars and taxis, and often on foot, the migrants came: a desperate, impoverished, modern-day diaspora spreading across a continent. They came with what few dollars and euros their families had scrounged up for them—and with a vague understanding of which countries were sympathetic and which were hostile.

Ahmed came wanting to study, hoping above all else that he could either return to a peaceful Syria one day or reunite with his parents abroad. He didn’t want to live off the Swedish welfare system; he simply wanted to be safe. Why had his cousins headed toward Sweden? “It’s a peaceful country,” Khalid explains. “I had heard it is good with people under 18. They have this humanity.”

“When they came to us eight months ago, they were thin, they were tired, they were afraid,” recalls Jacklin Said, who, with her husband Mohammed, houses Nabil, Ahmed, and Khalid in the city of Lund. “They couldn’t trust even us. Now they’re just starting to trust us. You have to learn them. We had luck. They are three great boys that want something in their lives.” Jacklin’s sister and brother house young refugees as well, part of a massive outpouring of public generosity in Sweden in the face of the crisis.

If the events of the past several months are any indication, however, governments will be less welcoming, and host-country populations less tolerant, than Sweden has been in the recent past. As borders start going up across Europe, the possibility grows more likely that Greece and Italy will become permanent refugee dumping grounds simply because of their proximity to Europe’s porous southern flank. The three cousins made it north in 2015. Far fewer have managed this journey in 2016.

After Sweden set up controls with Denmark, Denmark responded by setting up controls with Germany. Borders are also being secured (and walls constructed) across Europe, including in the Balkans and in several Southern and Eastern European countries. And in March, the EU and Turkey reached an agreement that would allow the EU to send a large number of refugees back to Turkey in exchange for financial aid and the vague promise of EU accession.

Unable to stop the conflicts that have spawned the refugee crisis, and equally unable to reach a political agreement within the EU on how to distribute the refugees across member states, Europe is militarizing its response. Those refugees who manage to evade the stepped-up naval patrols in the Mediterranean and survive a harrowing sea crossing are increasingly getting bottled up in squalid, heavily policed refugee camps on the southern edge of the continent.

With border patrols policing the Øresund Bridge, the era of free-flowing migration in Europe seems to be drawing to a close. “We looked with surprise to what was going on in Sweden,” recalls Venstre’s Marcus Knuth. “We tightened the rules. They did the complete opposite and said, ‘We want to be the asylum center of the world.’ That’s a beautiful thing—but at the height of the crisis, they were seeing 40,000 refugees a month. We were wondering when the system would collapse. It did in early January. From one day to the next, they shut the border. And they’re now imitating a lot of the rules we entered. Realistically, a small country like Sweden, they can’t keep admitting 40,000 a month.”