Iraq and the US have finalised a draft agreement that would permit the US military to remain in the country until 2011.
The proposed deal, annocuned on Wednesday, would also allow - with certain conditions -Iraq to try American troops charged with committing crimes in the country.
Baghdad will be given the initial chance to prosecute US personnel and Pentagon contractors accused of crimes occurring outside US bases and when off duty.
The deal also states that US troops should leave Iraqi cities by the end of June 2009 and withdraw entirely from Iraq entirely by December 31, 2011, unless Baghdad requests that they stay longer.
Ali al-Dabbagh, an Iraqi government spokesman, said: "The withdrawal is to be achieved in three years.
"In 2011, the government at that time will determine whether it needs a new pact or not, and what type of pact will depend on the challenges it faces."
Concerning the immunity os US personnel from prosecution, al-Dabbagh said: "Inside their bases, they will be under American law.
"Iraqi judicial law will be implemented in case [where] these forces commit a serious and deliberate felony outside their military bases and when off duty."
Under the draft the US does have the right to primary prosecution of troops and contractors who are undertaking military missions.
The Iraqi parliament and cabinet must pass the draft before the end of this year, when the current UN mandate expires.
The pact deciding how long troops would be allowed to stay in Iraq had been debated for months, with the right to prosecute emerging as the main sticking point.
The US had demanded exclusive jurisdiction over prosecution, but Baghdad said this undermined Iraq's sovereignty.
A deal is needed in order for the US military to have a legal basis to remain in Iraq.
The US currently has 147,000 troops in Iraq who rarely leave their bases unless on an authorised mission.
Yet, incidents have occurred of US troops committing crimes, including the rape and murder of a 14-year-old girl, and the murder of her family, in south Baghdad in 2006.
Four US soldiers pleaded guilty to the crimes in military courts.