BAGHDAD – The U.S. military on Thursday handed over to Iraqi authorities five Iranian officials it had detained in Iraq, and they would be transferred to Tehran shortly, Iraqi and Iranian officials said.

The detention of the Iranians, who include officials U.S. forces accused of arming Shi'ite Muslim militias at the height of Iraq's sectarian fighting, stoked tension between Tehran and Washington, also at odds over Iran's disputed nuclear program.

There are five, the Iraqi side has received them, said Yasin Majeed, a media advisor for Iraqi Prime Minister Nuri al-Maliki.

Iranian Foreign Ministry spokesman Hassan Qashqavi told state television the five would be handed over to the Iranian embassy in the next hours.

Iranian state television said three of the men were diplomats detained in a 2007 U.S. raid in Iraq's northern city of Arbil, while the rest were two other Iranians kidnapped elsewhere in Iraq by the U.S. occupation troops.

The U.S. military said it could not confirm the transfer or discuss specifics about any detainees. Transfers and releases are a private matter between (the U.S. military) and the government of Iraq, Captain Brad Kimberly said in an email.

Five men were originally detained in Arbil in 2007, but two of them were later released. There was no further information about the additional two Iranians released on Thursday.

U.S. President Barack Obama has been trying to improve ties with Iran since he took office in January, offering a new beginning in ties if Iran unclenches its fist.

But last month's disputed presidential election in Iran has again frayed relations between Iran and the West, with Iranian officials accusing the United States and Britain of interfering in its internal affairs.

The Iranians were detained in Arbil on suspicion of being members of the Iranian Revolutionary Guards' elite Qods force, which Washington says backs terrorists.

Washington has long accused Iran of fomenting violence in Iraq by arming, funding and training Shi'ite special groups, and tasking them with attacking U.S. troops or Sunni Muslim targets.

Iran rejects the charge of fomenting instability in Iraq and instead says the United States is to blame for the years of sectarian slaughter and insurgent violence that almost tore Iraq apart after the 2003 U.S.-led invasion.

Qashqavi, the Foreign Ministry spokesman, said the five were diplomats who had been held contrary to all international conventions.

He said they had been in contact with their families and the Iranian embassy after being transferred to Iraqi custody.

(Additional reporting by Hossein Jaseb in Tehran and Aseel Kami in Baghdad; Writing by Fredrik Dahl and Michael Christie)