A ceremony has been held in Basra to mark the official end of the six-year British military mission in Iraq.
UK combat operations ended as 20th Armoured Brigade took part in a flag-lowering ceremony with a US brigade.
Gordon Brown said the operation in Iraq had been a "success story" because of UK troops' efforts.
But the Stop the War Coalition said it had been a disaster and the 179 British military deaths were made more acute by the pointlessness of the UK presence.
Mr Brown, who held talks with Iraqi prime minister Nouri Maliki in Downing Street, said: "Today Iraq is a success story.
"We owe much of that to the efforts of British troops. Our mission has not always been an easy one, many have said that we would fail.
"Britain can be proud of our legacy that we leave there."
Mr Maliki said: "There are people in Iraq who want the government to fail but our army and armed forces are ready to face these challenges."
Although Britain may be pulling its troops out of Iraq a month ahead of schedule, the row over why they were sent there in the first place in support of a US-led invasion looks set to continue.
Opposition leader David Cameron called for an immediate full inquiry into the Iraq war, similar to the one carried out by the Franks Committee into the Falklands conflict.
He said: "After years of foot-dragging, I believe it is the time for the government to announce a proper Franks-style inquiry.
"Instead of starting in many months' time, it should start right now.
"There are vital lessons to learn and we need to learn them rapidly and the only justification for delay can, I'm afraid, be a political one."
In Basra itself, Defence Secretary John Hutton attended a memorial service for the military personnel killed in the conflict.
The focus was a memorial wall featuring the names of the 234 UK and foreign troops and civilians who lost their lives under British command in Iraq.
The names of those who died, including Italian, Dutch, Danish, American and Romanian troops, were read out before the Last Post was sounded and prayers said.
Then there was a loud roar in the sky as a Tornado aircraft flew over in tribute.
Those attending the service were adamant the British presence in Basra had been a force for good.
Lt Col Edward Chamberlain, commanding officer of Iraq-based battalion 5 Rifles, said: "We've been slowly working, as part of a coalition together over the six years, to achieve an end-state which is an Iraq which is secure, happy, at peace with itself and its neighbours.
"We're slowly but surely transitioning towards that."
Mr Hutton said British troops had fought "a long and hard campaign".
He added: "There's been no question about that, and we've paid a very high price.
"But I think when the history is written of this campaign, they will say of the British military: 'We did a superb job'."
British forces began their official pull-out last month when the UK's commander in the south of the country, Maj Gen Andy Salmon, handed over to a US general.
The civilian death toll in Basra as a result of the conflict is estimated at between 3,302 and 3,766, according to data from the Iraq Body Count.
Asked about the UK presence in Iraq, the country's president, Jalal Talabani, told BBC News that the mission had been one of liberation.
"In the past the British forces came to occupy against the will of the Iraqi people," he said.
"This time they came here to liberate Iraqi people from the worst kind of dictatorship."
But the UK Stop the War Coalition said: "The British soldiers will leave Basra in a much worse condition than they found it, its population depleted and demoralised, its infrastructure devastated."
BBC defence correspondent Caroline Wyatt says there is a sense of relief for many British servicemen and women that their final tour of Iraq is ending.
Some were serving on their fourth tour, taking them away from home for two years out of the last six.
But the BBC's John Simpson says many ordinary Iraqis in Basra are worried that the Americans who will replace them will be much more aggressive.