Dominic Raab has warned Iran it risks becoming an international “pariah” after the British ambassador was arrested during anti-government protests in Tehran.

The foreign secretary said the detention of Rob Macaire, without any grounds or explanation, was a “flagrant violation” of international law. He said Tehran was at a crossroads, with the prospect of continuing political and economic isolation unless it engages diplomatically with the west.

Macaire was said to be “safe and well” in the British embassy after he was released after more than an hour in custody. His arrest came as a wave of anti-government demonstrations broke out across the country following the admission Iranian forces had accidentally brought down a Ukrainian airliner killing all 176 people on board.

It is understood that the ambassador had been attending what had been billed as a vigil for the victims of the crash at the Amir Kabir University. However the event quickly turned into an anti-government protest at which point he was said to have left.

According to Iran’s Tasnim news agency, as he tried to make his way back to the embassy he was one of the people arrested outside the university on suspicion of organising, provoking and directing radical actions. It is unclear who he was arrested by.

In a statement, Raab said: “The arrest of our ambassador in Tehran without grounds or explanation is a flagrant violation of international law.

“The Iranian government is at a crossroads moment. It can continue its march towards pariah status with all the political and economic isolation that entails, or take steps to de-escalate tensions and engage in a diplomatic path forwards.”

The incident threatened to reignite tensions in the region just as they appeared to be easing.

Raab’s intervention came after the Iranians admitted they had brought down the Ukrainian Airlines flight 752 shortly after takeoff, killing all 176 people on board, in a “disastrous mistake”.

The crash happened hours after Iran launched a series of ballistic missile strikes on US bases in Iraq in retaliation for the killing of its top commander, Gen Qassem Suleimani, by an American drone.

The missile strikes failed to cause any casualties and the US president, Donald Trump, indicated he would respond by tightening sanctions rather than with further military action.