When historians look back to this era, they will wonder why we insisted on outsourcing our border control to a foreign country.

President Trump’s threat to close down the border with Mexico isn’t a sign of strength, but of frustration fading into desperation.

He is reacting with understandable alarm at a spiraling migrant crisis on the border, and looking to Mexico to address it because we are unwilling to do it on our own — not unable, unwilling.

There were more than 100,000 apprehensions at the border in March, an increase from the 76,000 in February. The numbers for both months were the highest in 10 years. The total for the fiscal year could hit a million, a historic surge completely overwhelming our capabilities.

We built our border facilities to hold single men, back when illegal migrants were largely adult males from Mexico, rather than family units from Central America. This means that they are ill-suited for the needs of women and children. Regardless, the sheer numbers are leading to authorities releasing migrants almost as soon as they are caught.

Homeland Security Secretary Kirstjen Nielsen warned Congress last week of “the real-time dissolution of the immigration system.”

It’s not that border control has been tried and failed; it hasn’t been tried. Thanks to court decrees and congressional enactments, we don’t permit ourselves to quickly return minors from Central American countries, or to detain them for any significant period of time. They get released, along with the adults accompanying them.

The asylum process is broken. The initial so-called credible-fear interview to determine whether asylum-seekers get to the next step of the process approves almost all of them, even if they are unlikely ultimately to win asylum. In the meantime, they are waved into the country and probably never removed.

The migrants coming in increasing numbers realize we are helpless to exclude them, and indeed, surrender to border patrol agents when they get here.

Congress could fix all this in an afternoon, with a few key changes in the law. Trump has a Nancy Pelosi problem much more than an Andrés Manuel López Obrador problem. But, since Pelosi is unmovable, Trump has to try to work the Mexican president.

Mexico has done more to play ball with the US under Trump than most people would have thought possible, yet all the migrants showing up at our border are still traveling through the country. Mexico doesn’t make controlling these migrants a high priority because they will end up here, not there.

The talk of cutting off the border isn’t aimed at the migrants, who largely don’t come through ports of entry, but at forcing the Mexican government to do more. Maybe the mere threat of the resulting economic disruption will work.

But if Trump goes through with closing the border, the strategy has some of the same weaknesses as the government shutdown earlier this year. Where does it end? If Mexico doesn’t act quickly, how long are we going to keep the border closed?

The longer it’s closed, the more pain will be felt in the US economy at a time when there are already signs of softness. What if Mexico initially buckles, then backslides? Will we shut down the border again, or threaten to?

Even if this gambit were guaranteed to succeed, it’s insane that a sovereign country of unparalleled power has tied its own hands such that it must try to bully and cajole a foreign nation to do immigration enforcement for it.

In a more rational world, Congress would take seriously the spectacle of US officials — and humanitarian organizations — scrambling to handle a flood of humanity showing up every day, and give them the legal authorities and resources to get the situation under control. That it won’t is a dereliction of duty of the highest order.

Twitter: @RichLowry