Theresa May has become the first major foreign leader to visit Iraq after Mosul was reclaimed from the clutches of Isis.

Iraq’s second-biggest city became a stronghold for the extremist group after it seized control in June 2014 – and in the fight to liberate it has left much of it in ruins.

For Ms May, the first British Prime Minister to visit Iraq since Labour’s Gordon Brown, it was also the first time she had been to a conflict zone.

“In Iraq we are working together to defeat Daesh and my visit comes at a critical moment as we see the caliphate collapsing with the fall of Mosul and Raqqa,” she told reporters.

“We want to ensure that Iraq can in the future provide that strong, stable and unified state that can provide the security, jobs and opportunities that all Iraqis want and deserve.”

She told ITV News: “Here in Iraq I have been pleased to meet with Iraqi forces who have been involved in that work against Daesh.

“That has been very important, and of course I have been meeting British troops who are training those Iraqi forces as part of the coalition effort.

“But we do need to ensure that we address the possibility of individuals from Daesh trying to set up elsewhere, and that is about ensuring there are no unstable areas where they can set up, but it is also about dealing with the terrorist threat in all the ways we can.

“That includes, for example, working to ensure that their hateful material is not being spread across the internet and inspiring others to conduct attacks.”

As she stepped off the rear loading ramp of an RAF Hercules C-130, she was given a helping hand by the new British Ambassador for Iraq, Jon Wilks.

Her first stop was Camp Taji, a coalition base north of the Iraqi capital, Baghdad, where around 80 British troops are currently based.

At a training complex on the camp, Ms May watched Royal Engineers training Iraqi security forces to detect and deactivate improvised explosive devices.

After watching one soldier practising with a metal detector, swiping it across an area in between two strips of orange tape, she quizzed him through an interpreter about the skills he was gaining, and he replied that they were very important.

Enjoying a cup of coffee in the warm Middle Eastern sun as she chatted to troops, she exclaimed “Oh wow” as she spotted a large cake decorated with a Union flag which had pride of place on a long table.

During the visit, the Prime Minister announced three commitments to counter the evolving threat from Isis and to manage the risk of foreign fighters returning to Europe.

These included a deepening counter-terrorism relationship with Iraq and £10m over the next three years to help build the country’s counter-terrorism capability.

She also said the UK would work with partners across the region to develop border infrastructure, watch-lists and biometric capabilities, to counter foreign fighter dispersal.

Ms May reiterated her call for more to be done to tackle terrorist use of the internet, which she said tech companies have begun to act upon by setting up the industry-led Global Internet Forum to Counter Terrorism.

“There is more for us to do, but we have had some success,” she said.

She also confirmed continuing support for Iraqi defence and security through officer training – including places for Iraqi students on high-profile UK courses at the UK military colleges and the Defence Academy.

British teams will also continue to train Iraqi forces.

Ms May later toured the Global Coalition operations centre before moving on to have talks with Iraqi Prime Minister Haider al-Abadi in Baghdad.

Their discussions, which continued for around 45 minutes, are understood to have focused on future defence and security cooperation between the two countries.

Mr Abadi thanked Ms May for Britain’s support in training, logistics and intelligence.

“Her visit is proof of the United Kingdom’s support in the fight against Daesh,” he said.

In the summer of 2014, Isis blitzed across the north and west of Iraq – capturing Mosul and even advancing to the edges of Baghdad.

The UK is one of 74 countries in the Global Coalition against Daesh.

RAF Typhoon and Tornado jets and Reaper drones have carried out more than 1,600 strikes, as well as surveillance, reconnaissance and refuelling missions against the terrorists over the past three years.

And as part of the UK’s role in the efforts, more than 600 British soldiers are currently deployed in locations across Iraq.