Ahmadinejad's convoy then traveled to the city of Karbala. The city, 90 kilometers (55 miles) south of Baghdad, is home to the shrine of Imam Hussein, a central Shiite martyr who is Imam Ali's son and the grandson of the Prophet Muhammad. He and his brother Abbas, buried nearby, were killed in a battle in the city that is central to Islam's Sunni-Shiite split.
This is Ahmadinejad's second visit to Iraq while in office. His previous trip in 2008 was the first by an Iranian president since Iran's 1979 Islamic Revolution.
He met Thursday with Prime Minister Nouri al-Maliki and other officials. He used his brief public remarks in Baghdad to emphasize the success of his own country with that of one-time foe Iraq.
The two countries fought a ruinous eight-year war that claimed hundreds of thousands of lives in the 1980s, but the 2003 U.S.-led invasion that toppled dictator Saddam Hussein ushered in a new era of warm relations between Tehran and Baghdad.
Najaf and Karbala have boomed economically since the invasion, thanks to religious tourism driven in large part by the hundreds of thousands of Iranian pilgrims who visit annually.
Associated Press writer Adam Schreck in Baghdad contributed reporting.