The House of Representatives has voted in favour of ordering President George W Bush to pull US troops out of Iraq.
Some Democrats want US troops to be brought home now
The bill imposes a 31 August 2008 deadline for the withdrawal of all US combat troops from the country.
It was passed by 218 votes to 212 by the Democratic-controlled House. Correspondents say it is the biggest challenge yet to Mr Bush's war policy.
The president quickly responded that he would veto the bill, which he called an "abdication of responsibility".
A grim-faced President Bush said the vote, which was largely along partisan lines, was an effort to "force me to accept restrictions on our commanders, an artificial timetable for withdrawal and their pet spending projects".
"This is not going to happen," he said.
The White House says legislators should allow more time for Mr Bush's "surge" strategy - which includes sending 28,000 extra troops to Iraq - to work.
The Senate is expected to vote next week on legislation similar to the House bill.
To pass the Senate version, the Democrats would need the support of about a dozen Republican senators.
The House vote was a victory for the Democratic leader, Nancy Pelosi.
"The American people have lost faith in the president's conduct of this war," she said during the debate on the bill, which was primarily to authorise $124bn (£62bn) in funding for US troops in Iraq and Afghanistan.
"The American people see the reality of war. The president does not."
However some Democratic representatives voted against the bill, because they want to put an immediate end to the war.
Others opposed it because it could make the work of military commanders more difficult.
Most Republicans opposed the legislation, which they said would represent an admission of failure in Iraq.
"The stakes in Iraq are too high and the sacrifices made by our military personnel and their families too great to be content with anything but success," Republican Roy Blunt said.
The House bill calls for the withdrawal of troops to begin as early as July 2007 if there is no evidence progress is being made in bringing order to Iraq.