One lesson of American history is that in times of war or crisis, American presidents, lawmakers and citizens often lose their minds. Another lesson is that they eventually regain their senses. When it comes to national security in the age of terrorism, it looks as though the national fever has broken.

When Congress passed the Patriot Act in October 2001, it gave the federal government greater authority for foreign intelligence and terrorism investigations. In those panicky days, the impulse was to say: Do whatever you have to do, and if the ACLU isn't happy, do more of it.

But even those who wanted to unleash the national security state didn't realize what they were creating. Not until 2013, when leaks by Edward Snowden exposed the actual scope of government surveillance, did we find out how far the Bush administration and the Obama administration were willing to go in sacrificing privacy.

Snowden let us know that by 2006, the National Security Agency was collecting and storing records of virtually every phone call made in the United States. Not just calls by al-Qaida operatives and Hezbollah sympathizers: calls by Serena Williams, Tom Hanks, Uncle Zeke and, of course, you.

The NSA created this program under a section of the Patriot Act that even the most paranoid anti-statists never dreamed could be stretched so far. It came as a particular surprise to one James Sensenbrenner of Menomonee Falls, Wis., who as the Republican chairman of the House Judiciary Committee actually wrote the law.

"I can say that if Congress knew what the NSA had in mind in the future immediately after 9/11, the Patriot Act never would have passed, and I never would have supported it," said Sensenbrenner after the Snowden revelations. When Congress renewed the crucial provision in 2011, many or most members still didn't know how it was being used.

On Thursday, a federal appeals court ruled that the domestic phone records collection is illegal because it goes way beyond what Congress had in mind and any plausible reading of the text or other legal powers. The relevant section of the Patriot Act, it said, "cannot be interpreted in a way that defies any meaningful limit." The government's broad reading of the law, it said, threatens "an unprecedented contraction of the privacy expectations of all Americans."

If Congress wants to let the NSA gather and store every phone record from every American from now till the end of time, the court declared, it will have to man up and say so.

That it has not done -- and may not be willing to do. The relevant section of the law expires June 1. The House Judiciary Committee recently gave bipartisan approval to the "USA Freedom Act," which would end the phone records collection and curtail the government's access to such information. It would be able to obtain these records only to investigate specific individuals for specific suspicions.

Hardliners oppose any effort to stop this indiscriminate snooping. Senate Republican Leader Mitch McConnell said the House bill would "neither keep us safe nor protect our privacy." Sen. Marco Rubio, R-Fla., insisted the phone records collection is needed to prevent the next 9/11.

In fact, as a way of preventing terrorism, it has been a gargantuan waste. The president's own blue-ribbon review panel extensively queried NSA officers and concluded that "there has been no instance in which NSA could say with confidence that the outcome would have been different without" the program.

The independent, congressionally created Privacy and Civil Liberties Oversight Board said it had never "directly contributed to the discovery of a previously unknown terrorist plot or the disruption of a terrorist attack." A federal district court reached the same conclusion.

Never have so many Americans had their privacy invaded to such a huge extent for such microscopic benefits. Politicians who, in the wake of 9/11, never had the idea that such measures were needed now tell us they are indispensable.

It's a classic exercise in covering bottoms. If no terrorism occurs while the program is in operation, the supporters can claim credit. If terrorism does occur, they can say they did all they could. If civil liberties suffer, that merely confirms our leaders' steely resolve.

In the years since the World Trade Center came down, many Americans, including the judges who ruled Thursday, have come to realize the sober fact that some steps to prevent terrorism are excessive, useless or both. It took a long time, but sanity is making a comeback.