Lawmakers agreed Thursday to a goal of scanning all cargo-containing ships before they leave foreign ports as Congress neared a deal on a major security bill to carry out the 9/11 Commission's recommendations.

In House-Senate negotiations on the bill, House and Senate Democrats pushed through a provision allowing a five-year window for radiation scanning technology to be put in place and giving the Homeland Security secretary authority to make exceptions.

Supporters said the measure was crucial to prevent the catastrophe of a ship entering a U.S. port with a nuclear device. Opponents said a risk-based approach taken in a port security bill passed last year was more effective.

The measure was part of the House bill that passed last January but was not included in the Senate version and is strongly opposed by the Bush administration, which said it was technically and economically unfeasible.

Negotiators also accepted House language that requires the inspection of all cargo on passenger planes within three years.

The maritime inspection issue was one of the last big sticking points to a compromise on the bill that Democrats put at the top of their agenda when they took over power last January. It was the first major bill passed in the House and moved through the Senate last March.

But formal negotiations were put off for months over issues such as White House opposition to provisions, since dropped, that would have given airport screeners collective bargaining rights.

"They had our highest priority," House Speaker Nancy Pelosi said of the 9/11 commissioners, who three years ago came out with 41 recommendations on how to improve national security in the wake of the Sept. 11, 2001, attacks on New York and Washington.

The White House and Congress have followed through on some suggestions, including creating a director of national intelligence to oversee the intelligence community and last year enacting a port security bill.

Former Rep. Lee Hamilton, D-Ind., a 9/11 commissioner, expressed "frustration that it has taken this long" to carry out other suggestions made by the panel.

Pelosi also pressed negotiators to reach a quick conclusion, with the hope of getting a bill to the president's desk before Congress departs for its August recess. That desire to move quickly was heightened by an intelligence report made public earlier this week that warned of the enhanced ability and intent of terrorists to strike within U.S. borders.

The bill, said Sen. Joseph Lieberman, I-Conn., at negotiations attended by relatives of those killed on 9/11, "has taken on even greater urgency in recent weeks" with terrorist acts in Britain, the intelligence report and Homeland Security Secretary Michael Chertoff's warnings that an assault could take place this summer.

Passage also would be a major victory for Democrats who laid out an ambitious legislative agenda that, except in rare cases such as an increase in the minimum wage, has yet to be enacted into law.

The bill changes the formula for distributing federal security grants to states to better reflect the risks of terrorism in each state. Currently states are guaranteed 0.75 percent of grant funds. That bill cuts that guarantee in half and approves $950 million annually over the next five years for state homeland security grants.

The legislation also authorizes separate grant programs for rail, transit and bus security at more than $4 billion for four years and creates a new program within the Homeland Security Department to improve communication links among state, local and federal officials.

Among the still-undecided issues was a dispute over whether the Homeland Security Department or the Department of Transportation should have jurisdiction over the awarding and distributing of grants for rail, transit and bus security.

Republicans also were demanding that language be added to provide immunity to citizens who report suspicious activity. They referred to an incident last fall where six Muslim scholars were removed from a flight in Minneapolis after other passengers said they were acting suspiciously. The imams have since filed a lawsuit, saying their civil rights were violated.

Republicans were also objecting to a provision that expands the Visa Waiver Program now open to 27 countries, while strengthening the electronic monitoring of people entering and leaving the country. They said the program has become a convenient way for terrorists to enter the country via nations such as Britain where no visa is required.