Tensions between US and Iran have heightened after Qasem Soleimani's death. (AFP)

The British government on Saturday advised UK nationals to avoid travelling to Iraq and Iran in face of heightened tensions in the Middle East following the US killing of a top Iranian commander in Baghdad.

"Following the death of Qasem Soleimani and heightened tensions in the region... We now advise British nationals against all travel to Iraq (and) we now advise against all but essential travel to Iran," Britain's Foreign Office said in a statement.

"The first job of any government is to keep British people safe," the statement said.

"Given heightened tensions in the region, (we) now advise people not to travel to Iraq, with the exception of the Kurdistan Region of Iraq, and to consider carefully whether it's essential to travel to Iran. We will keep this under review."

On Friday, the US military killed Soleimani in an air strike outside Baghdad international airport that shocked the Islamic republic and sparked fears of a new war in the Middle East.

The Islamic Revolutionary Guard Corps confirmed the death of the commander of its Quds Force foreign operations arm, and Tehran's clerical leadership promised "severe vengeance... in the right place and time".

In its statement, the British Foreign Office urged UK nationals in the region to "remain vigilant and monitor the media carefully."

On Friday, foreign minister Dominic Raab had said that while London had "always recognised the aggressive threat" posed by Soleimani and his Quds Force, "following his death, we urge all parties to de-escalate. Further conflict is in none of our interests."