Here’s an awkward truth. It’s easier to attract talented people from shithole countries than from Norway.

What kind of Norwegian, after all, wants to emigrate? Norway is rated by the United Nations as the happiest country on earth, a place where anyone with a bit of energy can succeed. The same is not true, of, say, Niger. Emigration is the best option for a Nigerien with ability, courage, and grit.

America, we might say, was built on the failure of shitholes. People came from all manner of poor and oppressive states, straightening their backs when they arrived. Your ancestors must have had some reason to make the journey. Where were they from?

Tsarist Russia was a shithole, even for most of its gentile subjects, let alone for its Jews. So was Sicily in the decades following Italian unification. It might be an understatement to use that word for Ireland during the potato famine. In each case, the people who got out — generally shrewder and more enterprising people — brought their ambitious genes to the U.S.

What made America different? Not any magical property in its water. Rather, a system of government that elevated the rules above the rulers and the individual above the collective. Suppose that, in 1803, Thomas Jefferson had decided to buy Haiti rather than Louisiana from Napoleon. Which, do you reckon, would be the shithole now?

The formula works anywhere. Africa has taken collective umbrage at President Trump’s profanity, but there are revealing differences among African states. I recently visited Uganda and the Democratic Republic of Congo, and was thunderstruck by how unalike they were.

Uganda’s GDP per capita is nearly three times that of the DRC, it is growing at twice the speed, and 1 in 3 Ugandans lives in poverty, as opposed to 3 in 5 Congolese. Kinshasa, the capital of the DRC, is the worst place I have set foot: dangerous, destitute, and dirty. Kampala, the capital of Uganda, might as well belong to a different solar system. Sure, there is poverty there by Western standards. But there is also an irrepressible sense of energy and optimism. Private schools are springing up, catering for one of the youngest populations on the planet. Everyone is busily engaged in making and selling things.

The two capital cities are not on different planets; they are in neighboring countries. How are we to account for such a colossal difference? It all has to do with the rule of law. Britain’s record in Uganda was checkered. We removed wealth from the country, and, until very late, denied full political rights to its people. At the same time, though, we built roads, schools, and clinics, and a legal system from which individuals might reasonably expect justice. Uganda was eventually brought to independence peacefully, with its institutions intact.

The same cannot be said, alas, of the resource-rich DRC, which used to be the personal property of the King of the Belgians. When the Belgians pulled out in 1960, they left almost no infrastructure, and chaos ensued. One kleptocrat followed another, and decent people fled, leaving swaggering brutes to lord it over a cowed population.

The wealth of a nation is not determined by its location, its geology, or its soil, but by its laws. As Adam Smith sagely put it in 1755, “’Little else is requisite to carry a state to the highest degree of opulence from the lowest barbarism, but peace, easy taxes, and a tolerable administration of justice.”

There used to be lots of Norwegian immigrants to the U.S., but rising prosperity at home now keeps most of them there. The waves of people that once came from Germany, Ireland, Poland, Italy, and Japan have been reduced to a trickle for the same reason. Even Mexico has seen a drastic reduction since NAFTA came into effect and one-party rule ended: In 2015, for the first time, more Mexicans crossed the border headed south than north.

Everything rests on the rule of law. It’s why I used to get so agitated over Barack Obama’s abuses of executive power. It’s why, by the same token, I’m alarmed when Republicans on the Senate Judiciary Committee order the Department of Justice to open a criminal investigation of Christopher Steele, seemingly because he has offended the president. Nothing in modern politics is more depressing than people’s indifference to process when they happen to favor the outcome.

These are, of course, first world problems. But in shitholes, leaders’ opponents fear murder rather than prosecution. We should never forget how precious the rule of law is, nor how easily it is lost.

Daniel Hannan, a Washington Examiner columnist, is a British member of the European Parliament.