Ahmadinejad, an ex-soldier, and Ortega, a former Marxist guerrilla, both came to power on populist platforms.
Ortega drove Ahmadinejad on a jeep tour of Managua's poorest slums, past houses made of plastic sheets and Sandinista supporters waving banners and holding up photographs of the Iranian leader.
Promises to fight corruption
Ortega, a close ally of Hugo Chavez, the Venezuelan president, began his term last week after winning November's election on promises to fight hunger and corruption.
Ahmadinejad is also close to Chavez, a fierce critic of George Bush, the US president, and visited him on Saturday before going to Nicaragua later in the evening.
Ortega said he would sign agreements with Ahmadinejad to help reduce poverty in Nicaragua, the Western Hemisphere's second-poorest country after Haiti. He gave no details.
"In our Iranian brothers we have a people, a government, a president willing to join with the Nicaraguan people in the great battle against poverty," Ortega said.
Nicaragua's troubled history
As president of Nicaragua in the 1980s, Ortega and his Sandinista movement confiscated businesses and farms after toppling a US-backed dictator.
Those policies, combined with a US economic blockade and a civil war against US-backed Contra rebels, plunged the coffee-producing country into chaos.
Since then, Ortega has said he learned his lesson and has dropped Marxism for a center-left program.
Following his stop in Nicaragua, Ahmadinejad will visit Ecuador, where the presidential race was recently won by Rafael Correa, another critic of US policies.