It’s never easy for a public leader to back down from a fight — particularly one he started. But President Donald Trump’s decision to reopen the federal government while negotiations on immigration proceed is the right move.

The toll from the monthlong closure had been mounting. The last straw may have come Friday, when major airports began seeing slowdowns for lack of air traffic controllers, who were among the 800,000 federal workers either furloughed or forced to work without pay. The shutdown has caused untold pain among Americans. We have seen Coast Guard members scrounging food shelves, federal workers standing in lines to receive free food from generous restaurateurs, and contractors losing business they may never recover. Signs of crumbling support were evident earlier this week when Senate Republicans reportedly vented about the shutdown in a private meeting.

Lawmakers now have a three-week window in which to come together and negotiate honestly about the nation’s border-security needs. The president, whose demands have been more varied than the weather, at one point allowed that border security could take various forms, including a wall. Stick with that flexibility, Mr. President. Allow lawmakers to figure out how best to spend $5.7 billion on security that will protect this nation’s borders and ports, detect those who overstay visas, spot drugs that come through legal entry points and catch those engaged in human trafficking.

If enough progress is made, it’s not impossible to think leaders could achieve what has eluded them for decades — a deal on comprehensive immigration reform that would include not just security but also humane ways to address refugees and this country’s need for workers. It needn’t take long. There is no facet of immigration reform that has not been discussed, analyzed and weighed over the years. What has been lacking is will.

A proposal that balances enhanced border security with immigration reform would be a win both sides could claim — if their bases would let them. The greatest danger in coming weeks will be from extremists at either end. Those on the far right can be expected to attempt to shame Trump for reopening government without gaining concessions. Those on the far left will attempt to force House Speaker Nancy Pelosi to grind Trump down and deny him the smallest victory. Both should be ignored. Pelosi held her ground when she needed to. If a factual determination is made that parts of the border are better guarded by a wall than other means, so be it. If it can be shown that this country would benefit from higher legal immigration limits rather than lower, done. And both sides should agree, as they have on occasion, that this nation must not deny a path to citizenship for immigrants who were brought to this country as children, and who know no other.

The prolonged federal shutdown — the nation’s longest — has been a shameful episode in this country’s history. It has proved, for Americans who did not already know it, the futility of these kinds of standoffs among leaders who consider it beneath them to work through their differences in the manner that has served this country since its beginning.

Let this be the end of this brutal tactic that has yielded so little and hurt so many. There is wisdom in one of Senate Majority Leader Mitch McConnell’s favorite phrases: “There is no education in the second kick of a mule.”

Americans need their government to function — effectively, continuously. It took less than four weeks and only a fourth of government shutdown to prove that. Leaders have many tools at their disposal as they seek the best ways to govern. A shutdown should never again be one of them.