The Senate passes a landmark bill for trying and questioning terrorism suspects, in a 65-34 vote that split along party lines.
Approval of the bill seemed assured earlier in the day Thursday, when an amendment aimed at preserving the right of all detainees to challenge their imprisonment in federal courts was narrowly defeated.
The debate came down to whether preserving longstanding civil liberties makes sense in an age of terrorist attacks.
A day after the House of Representatives passed a nearly identical version of the Republican-backed compromise, President Bush visited the Capitol on Thursday to rally his Senate allies.
"Our most important responsibility is to protect the American people from further attack," the president said. "And we cannot be able to tell the American people we're doing our full job unless we have the tools necessary to do so."
The White House asked Congress to draw up detainee legislation because the Supreme Court threw out the Bush administration's plan for detainee trials in June.