Ali al-Dabbagh, an Iraqi government spokesman, said the nine were handed over to Nuri al-Maliki, Iraq's prime minister, and were then transferred to the Iranian embassy in Baghdad.
Iranian state television quoted an unidentified Iranian embassy official as saying that the two captured in Irbil, who were described as diplomats, would return home later on Friday.
US officials claimed that the five captured in Arbil in January were either members or "associates" of the Iranian Revolutionary Guards's elite Quds Force, which Washington accuses of supporting terrorism.
"America says Iran getting a nuclear weapon could cause WW3 but I think it's more likely that America would cause WW3 by invading Iran"
Jack, Bangor, UK
Send us your views
Iran insists that all five detained in Arbil were diplomats working in a facility that was undergoing preparations to be a consular office.
The building, along with another Iranian office in Sulaimaniyah, was shut after the January 11 raid. Both offices - located in the two largest cities in Iraq's semi-autonomous Kurdish zone - reopened on Tuesday as Iranian consulates, Iraqi and Iranian officials said.
Tehran has denied stoking violence in Iraq, blaming bloodshed in Iraq on the US-led invasion to topple Saddam Hussein in 2003. Washington accuses Tehran of funding, training and arming militias in Iraq.
The US military announced it would release the nine this week after noting last month a sharp drop in mortar attacks on Baghdad's heavily fortified Green Zone. Many of those attacks have been blamed on Shia militias using Iranian-made weapons.
Ryan Crocker, the US ambassador to Iraq, has held three rounds of talks on security in Iraq with his Iranian counterpart this year.
Hoshyar Zebari, Iraq's foreign minister, urged Iran and the United States to hold a new round of trilateral talks with Iraq following the "positive" release of the nine Iranians.
"We have been saying that there should be a new round of talks between the three countries on the issues involving Iraq. These talks should happen this month," Zebari said.