As if on cue, riots broke out in a heavily immigrant suburb of Stockholm as soon as the media mocked President Trump for a vague warning about immigration-related problems in Sweden.

At a campaign-style rally over the weekend, Trump issued forth with a mystifyingly ominous statement. “You look,” he declared, “at what’s happening last night in Sweden.” What? Had the president invented a nonexistent terror attack? As it turned out, the reference was to a segment on Sweden he had watched on the Fox News show “Tucker Carlson Tonight” the previous night rather than to any specific event in the Nordic country.

The ensuing discussion quickly took on the character of much of the debate in the early Trump years — a blunderbuss president matched against a snotty and hyperventilating press, with a legitimate issue lurking underneath.

By welcoming a historic number of asylum-seekers proportionate to its population, Sweden has indeed embarked on a vast social experiment that wasn’t well thought-out and isn’t going very well. The unrest in the Stockholm suburb of Rinkeby after police made an arrest the other night underscored the problems inherent in Sweden’s immigration surge.

Sweden’s admirable humanitarianism is outstripping its capacity to absorb newcomers. Nothing if not an earnest and well-meaning society, Sweden has always accepted more than its share of refugees.

Immigration was already at elevated levels before the latest influx into Europe from the Middle East, which prompted Sweden to try to see and raise the reckless open-borders policy of German Chancellor Angela Merkel.

Sweden welcomed more than 160,000 asylum-seekers in 2015, and nearly 40,000 in October of that year alone. For a country of fewer than 10 million, this was almost equal to 2 percent of the population — in one year. The flow doubled the number of asylum-seekers at the height of the Balkans crisis in 1992.

The foreign-born proportion of the Swedish population was 18 percent in 2016, double that of 1990. As of 2015, the most common country of origin for the foreign-born was Finland, which makes sense as it’s a neighboring Scandinavian country. Next are Iraq and Syria.

Predictably, it isn’t easy to integrate people who don’t know the language, aren’t highly skilled and come from a foreign culture. Sweden’s economic polices don’t help. As a report of the Migration Policy Institute puts it politely, Sweden is “an interesting case” because “the state is committed to fostering large-scale immigration despite huge integration challenges in the labor market.”

There’s a stark gap in the labor-force-participation rate between the native-born (82 percent) and the foreign-born (57 percent). As the Migration Policy Institute points out, Sweden is an advanced economy with relatively few low-skills jobs to begin with.

On top of this, high minimum wages and stringent labor protections make it harder for marginal workers to find employment, while social assistance discourages the unemployed from getting work.

None of this is a formula for assimilation or social tranquility. In a piece for the London Spectator, Swedish journalist Tove Lifvendahl writes, “A parallel society is emerging where the state’s monopoly on law and order is being challenged.”

And the fiscal cost is high. According to Swedish economist Tino Sanandaji, the country spends 1.5 percent of its GDP on the asylum-seekers, more than on its defense budget. Sweden is spending twice the entire budget of the United Nations high commissioner responsible for refugees worldwide. Pressed for housing, Sweden spends as much on sheltering 3,000 people in tents as it would cost to care for 100,000 Syrian refugees in Jordan.

It’s little wonder that Sweden, where so recently it was forbidden to question the open-handed orthodoxy on immigration, has now clamped down on its borders. Sweden is a unique case, but clearly one of the lessons of its recent experience is: Don’t try this at home.