It will be closely watched by the US, which has more than 150,000 troops in Iraq.
"The talks we had were very positive," Ahmadinejad said at a joint news conference with Talabani.
"We have had good talks in a friendly and constructive environment. We have the same understanding of things and the two parties are determined to strengthen their political, economic and cultural co-operation."
He said the people of Iraq were going through "tough" times.
Al Jazeera's Mike Hanna reporting from Baghdad said that Ahmadinejad hopes to establish economic and political ties with Iraq.
He said: "The overriding theme, however, is an attempt to improve the security situation in the country."
"Iran's influence in Iraq is well-known, and it is believed that Tehran is more influential than the US, despite its huge military presence."
Ahmadinejad has said that the US is to blame for violence in Iraq and called for US troops to leave.
"Security for Iraq is security for Iran, and this does not suit the enemy because they do not want stability for the region, so they can continue their meddling in its affairs and justify the presence of its military," he said in an interview with Iraqi journalists.
Speaking on the eve of his trip to Baghdad, Ahmadinejad said his visit would help improve security in Iraq.
He said: "It will surely help strengthen the Iraqi nation and the government ... and peace and security in the region."
"Withdrawal of the occupying forces is in everyone's advantage."
Ahmadinejad's visit to Iraq is set to underline Western concerns about Iranian influence in the region and according to Washington, extends to aiding fighters in Iraq as well as destabilising Lebanon.
Washington says Tehran supplies weapons and training to fighters to attack US troops, a charge Tehran denies.