Iran has released eight Iraqi coastguards detained on Saturday after a clash on the Shatt al-Arab waterway, which marks the Iran-Iraq border.
The Shatt al-Arab is Iraq's main access to the Gulf
A ninth coastguard died of wounds sustained in the gunfight and his body will be repatriated later.
Iraqi officials say the Iranian Navy attacked the coastguards after they boarded a ship which was believed to be smuggling oil.
The incident has tested improved ties between the two countries.
Formed by the confluence of the Euphrates and Tigris rivers, the Shatt al-Arab is Iraq's main access to the Gulf.
The exact line of the border in the Shatt al-Arab is disputed, and was one of the causes of the Iran-Iraq War in the 1980s.
Basra Governor Muhammad al-Waili said the coastguards were driven by land to Iraq and received by Iraqi officials at 2300 (2000 GMT) on Thursday.
"An agreement was reached with Iran to free the guards... as well as the body of one of them... at the Shalamcheh border crossing," he said.
The commander of the Iraqi regional border force, Brig-Gen Abbas Musawi, told reporters that the coastguards had boarded an Iranian boat, Nur 1, that was smuggling oil 45km (27 miles) south of Basra.
The boat's Iranian captain alerted the Iranian navy by radio, Gen Musawi said.
Iranian navy speedboats then engaged the coastguards, he added.
Iran detained eight British servicemen for three days in 2004 after they allegedly strayed over the maritime border. The UK claimed the men were "forcibly escorted" into Iranian territorial waters.