The Iranian president, Hassan Rouhani, described Afghanistan as an occupied nation while in Kabul to celebrate the Persian new year on Thursday, saying Soviet and Nato forces had brought violence and extremism to the country.

Relations with the west have warmed slightly since Rouhani took office, but Iran has always been unhappy about having a US presence on its doorstep and is strongly opposed to a draft security agreement that would keep US troops in Afghanistan for another decade.

Rouhani did not refer directly to the US or Nato, whose troops have been fighting on Afghan soil for over a decade, but his comments about "two occupations" left little room for doubt.

Soviet forces arrived in Afghanistan in 1979 and stayed for a decade of escalating conflict. US and Nato troops helped topple the Taliban government in 2001, and have remained in the country to fight a spreading insurgency ever since.

"[The occupations] brought the unfortunate seed of violence, which has damaged the lives of people and this country," Rouhani said, adding that decades of war had also introduced extremists to Afghanistan.

"My country, the Islamic Republic of Iran, has condemned both occupations and has helped the people of Afghanistan in both periods of time," the Associated Press quoted him as saying at a day of celebrations at the presidential palace in Kabul that were also attended by the presidents of Tajikistan and Pakistan.

Tehran has poured millions of dollars' worth into direct support for the Afghan government and networks of soft-power projects from schools to mosques and media outlets. It has also reportedly established ties with the Taliban, though relations with the hardline Sunni group were poor when they ruled the country.

The Afghan president, Hamid Karzai, has warned US forces in the past that heavy-handed military tactics risk making Afghans see them as occupiers, but never gone as far as Rouhani.

Foreign combat forces are due to leave the country by the end of this year, but if the bilateral security agreement is signed, a few thousand troops will stay on to train Afghan soldiers and hunt down militants from al-Qaida and asscociated groups along the border with Pakistan.

Karzai has refused to sign the agreement, but he will step down this year, with elections due to take place on 5 April to choose a successor. All the main candidates to replace him say they would finalise the pact soon after taking office.