President Hassan Rouhani delivered a searing indictment of western governments in a speech in New York saying they were responsible for sowing the seeds of the outbreak of extremism that has brought turmoil to the Middle East and demanded that they “acknowledge their errors” and apologise.

“Certain intelligence agencies have put blades in the hand of madmen, who now spare no one,” Mr. Rouhani told the United Nations General Assembly. “Currently our peoples are paying the price. Today’s anti-Westernism is the offspring of yesterday's colonialism. Today's anti-Westemism is a reaction to yesterday’s racism.”

“The strategic blunders of the West in the Middle-East, Central Asia, and the Caucuses have turned these parts of the world into a haven for terrorists and extremists,’ President Rouhani declared. “Military aggression against Afghanistan and Iraq and improper interference in the developments in Syria are clear examples of this erroneous strategic approach in the Middle East.”

The Iranian leader, who had a first historic meeting with David Cameron in New York earlier this week, openly suggested that flexibility by the West in the ongoing talks on Iran’s nuclear ambitions and a deal before a deadline set for November would open the way to Iran cooperating more fully in trying to confront the threat raised by the extremist groups. He made direct reference in the speech to both al-Qa’ida and Daesh, the Arab name for Isis.

If a nuclear agreement is struck, he said, “then an entirely different environment will emerge for cooperation at regional and international levels, allowing for greater focus on some very important regional issues such as combating violence and extremism in the region.”