Iran's top leader has said he is against US intervention in neighbouring Iraq, where Sunni fighters opposed to Tehran have seized a number of towns and cities.

Ayatollah Ali Khamenei said on Sunday that Iraq's government and its people, with help of top clerics, would be able to end the "sedition" there, saying "extremists" are hostile to both Shia and Sunnis who seek an independent Iraq.

"We strongly oppose the intervention of the U.S. and others in the domestic affairs of Iraq," Khamenei was quoted by the official IRNA news agency as saying, in his first reaction to the crisis.

"The main dispute in Iraq is between those who want Iraq to join the US camp and those who seek an independent Iraq," said Khamenei, who has the final say over government policies.

"The US aims to bring its own blind followers to power since the US is not happy about the current government in Iraq."

Earlier on Sunday Iran's President Hassan Rouhani said some countries "feed terrorists by their petrodollars", in a veiled reference to the Arab Gulf states, and warned that such support would come back to haunt them.

"Rest assured, tomorrow will be your turn. The barbarous terrorists will go after supporters of terrorism in the future," Rouhani said.

Shia Iran supports the Shia-led government in Baghdad, and has said it would consider any request for military aid.

The commander of Iran's elite Quds Force, General Ghasem Soleimani, was reportedly in Iraq last week to consult with the government there on how to stave off insurgents' gains.

Soleimani's forces are a secretive branch of Iran's Revolutionary Guard that in the past has allegedly organised Shia armed group to target US troops in Iraq and, more recently, was involved in helping Syria's President Bashar Assad in his fight against Sunni rebels.

The Iraqi former ruler Saddam Hussein fought an eight-year war with Iran in the 1980s that left more than a million dead on both sides. Many current Iraqi leaders spent years in exile in Iran.