It took compromise, cajoling and a hard push from President Bush, but Congress finally passed legislation reforming the country’s intelligence community.

The bill was long overdue, coming more than three years after intelligence failures allowed terrorists to strike and almost two years after a war predicated on bad information. Nonetheless, passage is welcome.

Maine Sen. Susan Collins deserves most of the credit for the legislation. She was the legislation’s primary author, along with Connecticut Democrat Joseph Lieberman, and she was the point person in negotiations between the House and Senate.

Along with many Sept. 11 victim families, Collins was the bill’s leading advocate, wrestling with a recalcitrant House of Representatives, whose leaders threatened the bill’s passage by blocking a floor vote.

Much of the legislation that shuffles its way into law in Washington is motivated by self-interest: Bringing home a little pork, funding a pet project, helping out a favored political contributor or large home-state employer.

This bill is different. It required overcoming a turf war between advocates of a director of national intelligence, which the bill contained, and the Pentagon, always protective of its budgetary power.

The work has largely been thankless, but Collins has done it with a positive attitude and determination.

Here’s what Sen. John Rockefeller, a Democrat from West Virginia, told The New York Times about Collins: “I’ve been in Congress for 20 years, and I’ve never seen any person exercise the leadership, the restraint, the good humor, the toughness to stand up against whoever she had to stand up against than Susan Collins.”

That’s high praise, which is well-deserved.

The bill is not without flaws. The authority of the new director of national intelligence has been curtailed from its original design, and some of the counterterrorism provisions in the bill push the bounds of civil liberties. But in the end, the compromise legislation is a good foundation on which to build a better intelligence system.

For that, Collins deserves credit.