By Caroline Wyatt
Defence correspondent, BBC News
Gordon Brown has announced detail of the UK withdrawal from Iraq
For the first time, a rough official timetable for British forces to leave Iraq has been made public.
Prime Minister Gordon Brown has said that the British mission there will end no later than 31 May, 2009.
He is expected to provide further details of the withdrawal to Parliament on Thursday.
His visit to Baghdad came after the Iraqi cabinet agreed a draft law on Tuesday, which should be approved by the Iraqi parliament before the end of the year.
It states that foreign forces - including Britain - will have until the end of next July to leave the country.
US forces are covered under a separate Status of Forces Agreement, which will allow them to stay until the end of 2011.
Car bomb attack
This statement marks the beginning of the end of the British military mission in Iraq, almost six years after the US-led invasion in 2003.
British troop numbers peaked in Iraq that year, with 46,000 in total, in the operation which toppled Saddam Hussein from power and plunged the country into years of deadly insurgency and brought it to the brink of civil war.
Some 178 servicemen and women from Britain have lost their lives in Iraq since the invasion.
Only 4,100 British forces are still left in Basra, the majority of them based at the air station outside the city.
Their main task now is training and mentoring Iraqi forces, including the Iraqi Army and Iraqi Navy, the latter a key task, as Iraq's oil platforms need to be protected.
Once the bulk of British forces have left, a few hundred are expected to remain to continue that training mission.
On Wednesday, the day Gordon Brown announced the planned withdrawal, a loud explosion rang through central Baghdad.
It was a car bomb, followed by an improvised explosive device (IED), which killed 18 and left 52 people injured, an indication that life for most Iraqis is still far from normal.
The security situation has improved markedly since the US troop surge last year, but every day still brings bombs, IEDs or shootings somewhere in Iraq.
Cities such as Mosul, in the north, still see regular violent clashes, in a nation that feels bruised, battered and bloodied by more than five years of conflict.
However, Basra, home to the British area of operations in the south, has been much more peaceful since Operation Charge of the Knights, the operation led by the Iraqi Army in March.
It was designed to rid the city of Shia militias and gangs of criminals who had controlled much of the city.
British forces helped train Iraq's 14th Division, which took part in the mission, but the UK played only a minor role in the operation itself, apparently taken by surprise by its timing.
Critics said the UK's earlier decision to leave Basra Palace and withdraw to the air station in December 2007, allowed a security vacuum to develop in the city which only ended with the successful Iraqi military offensive.
The British have been training the Iraqi military in Basra
When British troops withdraw, it is expected they will hand over Basra air station to US forces, who will remain in the south to ensure security and protect the vital supply route that leads from Kuwait to Baghdad.
The withdrawal is likely to be met with a sense of relief in Britain that a controversial and unpopular war is at last drawing to a close.
Initial expectations that the invasion in 2003 could be quick and light, with US and UK forces and their allies handing the country back rapidly to a new Iraqi government, were dashed in the sectarian clashes that followed.
Iraqis now hope their country is finally on the path to a more peaceful future where it can determine its own path politically and economically, and is able to prosper without the presence of foreign armies on its soil.