This has been a state visit by motorcade, and mostly behind closed doors.
By Hugh Sykes
BBC News, Baghdad
Mr Maliki (r) told Mr Ahmadinejad Iran had "helped enormously"
President Mahmoud Ahmadinejad travelled from Baghdad airport to the city centre in a black BMW with a heavily armed escort.
He was welcomed by Iraqi President Jalal Talabani at his compound near the River Tigris. They stood solemnly side by side as a band played the national anthems of each country, starting with Iran's.
The two men then walked along a red carpet, inspecting a guard of honour. The Iranian president shook hands with members of the Iraqi government, and a young girl and boy presented him with flowers.
Later, at a news conference where his Arabic was translated into Farsi for his guest, President Talabani greeted President Ahmadinejad warmly with a double handshake and a beaming smile.
The Iranian president said he was "truly happy" to be visiting an Iraq "without the dictator" Saddam Hussein. He did not acknowledge America's role in his removal.
The Americans are keeping their distance from this visit.
Security cover for the visit appeared to be chiefly Iraqi
They accuse Iran of funding and arming Shia militias here.
Asked about this and about the visit, US military spokesman Adm Gregory Smith said Washington welcomed positive influence from Iran, but added that Tehran needed to "find ways to turn around" what he termed negative influence in Iraq.
Iran says much the same about the US - before he left Tehran, Mahmoud Ahmadinejad told reporters: "It is the American practice to present others as guilty wherever they are defeated. Is it not funny that those with 160,000 forces in Iraq accuse us of interference?"
The visiting president also saw Prime Minister Nouri Maliki at his offices inside the heavily fortified Green Zone.
Entering the Green Zone usually involves passing through American checkpoints, but security on the way into the zone for Mr Ahmadinejad was provided by Kurdish peshmerga forces supplied by the Kurdish Iraqi president.
Adm Smith confirmed that "'the primary responsibility" for security during the Iranian president's visit was Iraqi, but he said the coalition would lend "support as required".
There has been a lot of symbolism during this visit, and not a lot of substance.
But the symbolism is important.
Iran wants to be seen to be playing a positive role in Iraq and Mr Ahmadinejad made it clear he believes Iranian and Iraqi stability are mutually dependent.
Iran also has ample instability to contend with already - to the east, across the border in Afghanistan.
And the Iraqi prime minister told Mr Ahmadinejad that Iran had "helped enormously with security and stability in Iraq".
Iran is also helping Iraq to reduce its chronic shortage of electricity, with new transmission lines to the Iraqi national grid from power stations in Iran.
And there is something strange.
In an overwhelmingly Arab region, it is non-Arab Iran that is establishing the strongest ties with Iraq. No comparable Arab leader has visited Iraq officially since the fall of Saddam Hussein.