The conditions and deadline are part of a $124.1bn emergency spending bill, including $95.5bn to continue fighting the wars in Iraq and Afghanistan this year.
The White House has threatened a presidential veto of the measure, which could be debated in the full House as early as next week, and was facing resistance in the senate on Thursday.
David Obey, the House Appropriations Committee chairman, said as his panel began a heated debate on the war: "We are trying to deliver a message to the politicians in Iraq that we are not going to sit around forever watching them dither, watching them refuse to compromise, while our troops die."
The legislation marked the first time a congressional committee voted to put binding limits on the duration of the war in Iraq.
As the house panel voted, the senate wrangled over a separate Democratic resolution calling on George Bush, the president, to bring US troops home by March 31, 2008.
That measure failed on a 50-48 vote in which 60 votes were needed for passage, but anti-war senators may try again in the spending measure.
"This is a process. Step by step, we're moving towards having our soldiers, sailors, and marines return home from Iraq.
That is what this is all about," Harry Reid, the senate majority leader, said before the vote.
Even if congressional Democrats fail to enact legislation to end the increasingly unpopular war, they are hoping to accomplish two things - to deliver on last year's campaign promise that they would try to bring the troops home and to apply pressure on the Iraqi government to take more responsibility for security, a goal Bush also seeks.
"This is a civil war and the Iraqis have to take this up themselves," John Murtha, a Democrat representative, said, adding that the war was ruining US military capability.
Congress hopes to finish work on the war-spending bill by next month, when the Pentagon says it will run out of money to wage war.
Next week, the Senate Appropriations Committee will write its version of the war-spending bill.
Robert Byrd, the committee chairman, said on Wednesday: "The Congress of the United States will not support an unaccountable, open-ended war in Iraq."
To entice wavering legislators to vote for the bill, House Democrats have included $6.4bn, significantly more than Bush sought, in new money to help southern states rebuild after devastating hurricanes in 2005.