An American, identified as Randy Michael Hultz, was shown on television in a US military uniform with no insignia, flanked by two members of parliament from Shia cleric Muqtada Al-Sadr's movement, including the parliament's first deputy speaker.
He was handed over to the United Nations mission in Baghdad, which transferred him to the US embassy. Washington confirmed he was a US citizen but released no further details. In brief remarks to Iraqi journalists hastily convened to witness his release, Hultz said he had deployed to Iraq in 2003 and initially served there as a soldier for 15 months.
He remained in Iraq "in a civilian capacity from then until June of 2011, when I was taken hostage by elements of Yom Al-Maoud," he said, referring to the Promised Day Brigade, an offshoot of Sadr's Mehdi Army militia.
"I was taken inside Baghdad and have been kept in and around different locations within the city by Al-Maoud. It was explained to me that my release has been for humanitarian purposes and there was no exchange involved."
Journalists were shown two identity cards with the name Randy Michael Hultz, one showing he had been a soldier and the other showing he had been employed as a contractor.
Sadrist lawmakers repeatedly described him as an American soldier and earlier identified him as Randy Michaels. However, the Pentagon says none of its serving troops have been listed as hostages in Iraq since the remains of the last missing soldier were recovered last month.
Maha Al-Douri, a lawmaker from Sadr's bloc, said: "We declare the release of the American soldier, Randy Michaels, without any compensation, according to the instructions of Muqtada Al-Sadr, as a gift from him to the soldier's family and to his people, and to correct the image of Islam."
Qusay Al-Souhail, deputy parliament speaker, said the leadership of the Promised Day Brigade had made the decision to free their captive in light of the confirmation that US troops had withdrawn from Iraq.
The UN mission in Baghdad, UNAMI, confirmed that Souhail and Douri had handed over a US citizen and said it had passed him to the US embassy.
A US State Department official in Washington said: "We can confirm that the UNAMI has transferred a US citizen to the US embassy in Baghdad, which is providing consular assistance. Due to privacy considerations, we are unable to provide additional information."
Nine years after the invasion that toppled Saddam Hussein, the United States withdrew its forces from Iraq in December, with the exception of a few hundred service members stationed as part of the diplomatic mission at its embassy.
The US mission still includes 2,000 diplomats and, as of last year, 14,000 civilian contractors. The embassy says the number of contractors has declined since then but does not release updated figures.
Sadr's Mehdi Army fighters controlled swathes of Baghdad and southern Iraq until they were largely defeated by Iraqi government forces and US troops in 2008.
Sadr disbanded most of the Mehdi Army and joined mainstream politics, and his followers are part of the governing power-sharing coalition.
The Promised Day Brigade and other Mehdi Army offshoots continued to battle US forces and have claimed responsibility for kidnappings of foreigners. Those groups have mainly said they are disarming now that US troops have left.