"The world, especially Europe, has a humanitarian and historic duty to help these displaced and stranded people," Rouhani said, quoted on his website.
Europe has been facing an unprecedented influx this summer of people seeking refuge, many of them from war-torn Syria but also from Africa.
The United Nations refugee agency, UNHCR, said Saturday that 366,402 migrants have crossed the Mediterranean to Europe this year, with 2,800 killed or missing en route.
"We are glad some European countries have taken positive measures to save the displaced immigrants and we hope that other EU countries would join this trend," said Rouhani.
Rouhani, speaking as he received Hungary's new ambassador, Janos Kuac, said Iran hosts more migrants from neighbouring countries, mostly Afghanistan and Iraq, than any other state in the region.
"All the problems stem from the threat of radical groups and terrorists that have caused fear and displacement among innocent people in the region," he said.
Hungary is a key point of entry to the EU for migrants and refugees from the Middle East and Asia trekking up through the Balkans to Western Europe after crossing the Mediterranean to Greece, AFP reports.
Some 50,000 migrants entered Hungary last month via the western Balkans. Hungary has responded with tough new anti-immigration measures.
Its right-wing prime minister, Viktor Orban, has said Hungary did not want more Muslim migrants and warned Europe would lose its Christian identity.