WASHINGTON - House and Senate negotiators late Monday agreed to a sweeping $662 billion defense bill that requires military custody for terrorism suspects linked to al-Qaeda, including those captured within the United States, and indefinite detention without trial for some suspects.

President Obama and his national-security team had appealed to lawmakers for last-minute changes to the bill to give the executive branch greater flexibility on whether to treat suspected terrorists as prisoners of war or criminals. Facing a White House veto threat, leaders of the Armed Services Committees said they had added language on national-security waivers and other slight revisions that they hoped would ensure the administration's support.

"We took significant steps to address the administration's concerns," Rep. Adam Smith of Washington state, the top House Armed Services Democrat, said at a news conference.

The White House had no immediate comment late Monday, and it was unclear whether it would hold firm on its veto threat.

Overall, the bill would authorize $662 billion for military personnel, weapons systems, national-security programs in the Energy Department, and the wars in Iraq and Afghanistan in the fiscal year that began Oct. 1.

Reflecting a period of austerity and a winding down of decade-old conflicts, the bill is $27 billion less than Obama requested and $43 billion less than Congress gave the Pentagon for the year before.

The legislation would impose tough new sanctions on Iran, targeting foreign financial institutions that do business with the Central Bank in Tehran. Senate Armed Services Chairman Carl Levin (D., Mich.) said that the negotiators made some changes to address Treasury Department concerns, but that the legislation was "96 percent" of what the Senate had unanimously backed.

The lawmakers said they hoped the House and Senate could vote on the bill Wednesday and send it to the president.

The issue of how to handle captured terrorist suspects has divided Obama's senior national security officials and Congress as well as Democrats and Republicans.

The administration insists that military, law enforcement, and intelligence officials need flexibility in prosecuting the antiterrorism campaign. Obama points to his administration's successes in eliminating Osama bin Laden and radical Islamic cleric Anwar al-Awlaki.

Republicans counter that their efforts are necessary to respond to an evolving, post-Sept. 11 threat, and that Obama has failed to produce a consistent policy on handling terror suspects.

The bill would require that the military take custody of a suspect deemed to be a member of al-Qaeda or its affiliates and who is involved in plotting or committing attacks on the United States, with an exemption for U.S. citizens.

Responding to appeals from Obama, Defense Secretary Leon Panetta and FBI Director Robert Mueller, the lawmakers added a provision that says that nothing in the bill will affect "existing criminal enforcement and national security authorities of the FBI or any other domestic law enforcement agency" with regard to a captured suspect, "regardless of whether such ... person is held in military custody."

The bill also says the president can waive the provision based on national security. Originally that authority rested with the Defense secretary.

House and Senate negotiators dropped several provisions in the House bill that also had drawn a veto threat, including a requirement of military tribunals for all cases.

"After a decade of war against al-Qaeda and its affiliates under the authorization for the use of force of Sept. 18, 2001, it is long past time provide a statutory basis relating to military detention under that authorization," Levin said in a statement.

The legislation would deny suspected terrorists, even U.S. citizens seized within the nation's borders, the right to trial and subject them to indefinite detention. The lawmakers made no changes to that language.

The revisions were not sufficient for at least one civil rights group.

"The so-called 'changes' to the detainee provisions that came out to conference are cosmetic at best," said Raha Wala of Human Rights First. "They do little to fix the underlying problems with the bill. The president has no choice now but to veto, both for the sake of our national security and the rule of law."

The bill would go after foreign financial institutions that do business with Iran's central bank by barring them from opening or maintaining correspondent operations in the United States. It would apply to foreign central banks only for transactions that involve the sale or purchase of petroleum or petroleum products.

The petroleum penalties would only apply if the president, in six months, determines there is a sufficient alternative supply and if the country with jurisdiction over the financial institution has not significantly reduced its purchases of Iranian oil. It also allows the president to waive the penalties based on national security.

In a reflection of the uneasy relationship between the United States and Pakistan, the bill would freeze some $700 million in assistance until Pakistan comes up with a strategy to deal with improvised explosive devices.