US troops will withdraw from Iraq by December 31 2011 and American and British soldiers deployed there in the interim period could face prosecution in Iraq's courts for serious, premeditated "off-duty" crimes under the terms of a draft status of forces agreement outlined yesterday by officials in Baghdad and Washington.

The draft agreement, which is intended to replace the UN security council mandate that legitimised the US-led invasion in March 2003, and subsequent occupation, follows months of fraught negotiations. It must be ratified by the Iraqi parliament before the end of the year.

Passage is far from guaranteed. Iraq's most influential Shia cleric, Grand Ayatollah Ali Sistani, said last week that any pact must have the support of Iraq's people and political parties before it could be endorsed. Some of the deal's terms may also prove controversial in the US.

But the agreement, if implemented, would mark a milestone in the slow, often painful evolution of independent, Iraqi self-government since the overthrow of Saddam Hussein five years ago. It also represents a climbdown by the Bush administration, which had previously refused to set a deadline or timetable for a troop withdrawal.

Ali al-Dabbagh, the Iraqi government spokesman, said US forces would pull out of Iraqi towns and villages by the middle of next year and withdraw from the country as a whole by the end of 2011. But he left open the possibility that some US and other forces might be asked to stay beyond that date if needed.

"The withdrawal is to be achieved in three years," Dabbagh said. "In 2011 the government at that time will determine whether it needs a new pact or not. What type of pact will depend on the challenges it faces." Dabbagh indicated US troops and Pentagon contractors would be subject to US law while on base or while conducting off-base "military missions" - a potentially catch-all definition since US forces rarely venture off base.

But he added that "Iraqi judicial law will be implemented in case these forces commit a serious and deliberate felony outside their military bases and when off-duty". In such instances, American offenders would be held in US custody but could be surrendered to the Iraqi authorities for questioning and possible trial.

A series of incidents allegedly involving US forces and Pentagon employees which led to the death of Iraqi civilians and, in one case, the alleged rape of a 14-year-old girl, has outraged public opinion and added to pressure for tougher rules.

Officials in Washington confirmed yesterday that a compromise on prosecutions and a withdrawal date had been reached but urged caution. "There is a text that people are looking at," a state department spokesman said. "Nothing is done until everything is done. Everything isn't done."

The draft agreement, if implemented, would also prevent the US military from continuing to hold Iraqi suspects without charging them with crimes under Iraqi law. At present the majority of the 18,000 people held by coalition forces have not been charged with any offence.

British soldiers serving in Iraq are likely to be subject to the new rules from next year. Asked this week about the future status of British forces, the Ministry of Defence said: "Our requirements are very similar to those of the US. We intend to use the Iraqi/US text as the basis of our agreement."

The mooted deal comes against a backdrop of growing pressure from Iraqi public opinion and from Iraq's powerful majority Shia neighbour, Iran, for the departure of US and other foreign forces. Iraq's nationalist prime minister, Nouri al-Maliki, has moved successfully in recent months to assert army and police control over areas such as Basra, although levels of violence have been rising again in recent weeks.