The former President of Iran, Mohammad Khatami, has branded US attempts to impose Western-style democracy in the Middle East as "a great joke".
Mr Khatami was critical of the US-led military campaigns in Afghanistan and Iraq, which he said had led to more Muslims supporting al-Qaeda.
In a wide-ranging interview with the BBC, Mr Khatami, said he was committed to fighting extremism around the world.
He also called on US and UK to leave Iraq in an effort to reduce violence.
Mr Khatami, the most senior Iranian to visit the UK since 1979, served two terms as Iranian president from 1997 until 2005, when he was replaced by the current leader, Mahmoud Ahmadinejad.
Speaking at Chatham House, a foreign policy think-tank in London, Mr Khatami said Iran was supporting efforts to build strong governments in Iraq and Afghanistan.
But he said the near neighbours of both countries should be in charge of solving the problems of insecurity, and that "foreign alien forces" should leave the region as soon as possible.
"This has been a terrible idea. You know, the Americans are suffering, and you will see the result of this mistake in the upcoming polls in the United States."
The idea that Western-style democracy could be "exported" to the Middle East was flawed from the beginning, Mr Khatami said.
"It's a great joke - the greatest joke that Mr Bush said, that he would like to export democracy to the Middle East.
"Democracy is not something to get exported."
During his term in office Mr Khatami was regarded as a reformist leader, whose policies were not always supported by clerics on Iran's ruling Guardian Council.
Mr Khatami now maintains that he aims to tackle extremism wherever it exists, and to break down barriers between the great religions and civilisations of East and West, says the BBC's diplomatic correspondent, James Robbins.
He condemned what he called "insurgent terrorism" in Iraq but also branded the Bush administration extremist.
During the speech he also urged British Muslims to obey UK law, saying they are "British first". He said that the wearing of the scarf or veil was a woman's personal choice, and she should not be obliged to do so.
His visit to the UK has made Mr Khatami the most senior Iranian politician to visit the country since the Islamic Revolution in 1979, but has also sparked protests.
He was forced to enter Chatham House through a side entrance to avoid several hundred demonstrators protesting against Iran's human rights record during his time in office.