The Queen has praised intelligence officers for their response to “changing threats” to the UK, in a secret visit to MI5’s head office.

She was pictured speaking to director general Sir Andrew Parker outside the headquarters in London on Tuesday lunchtime, after giving a speech to staff based there.

The Queen praised their “tireless work” to “keep our country safe” and said “I am always struck by the remarkable resolve with which you carry out your vital role”.

Queen Elizabeth II thanked the staff during the visit. (Press Association)

Read more: How Sussex Royal loss will impact Harry and Meghan

In a speech, she said: “There will no doubt continue to be significant threats and challenges ahead. But on each of my visits to MI5, I have been impressed by the way that you have adapted to the changing threats to our nation.

“Whether responding to the threats from the Nazis or the Cold War, domestic terrorism or the cyber sphere, you have always demonstrated the utmost commitment to your motto: ‘Regnum Defende’.

“Because of the nature of your work, it is without public recognition, so it is on behalf of the country that I say to you all, thank you.”

Queen Elizabeth II during a visit to the headquarters of MI5 at Thames House. (Press Association)

Queen Elizabeth II looks at artifacts relating to MI5 D-Day operations Sir Andrew. (Press Association)

Read more: Harry and Meghan announce transition details as they confirm end of Sussex Royal branding

MI5’s motto means defence of the realm.

Sir Andrew gave the Queen a tour of MI5’s private museum, where he showed her artefacts relating to double agents who helped deceive the Nazis over the site of the Second World War D-Day landings.

During the tour, he described the MI5 double agent operation as “the most important thing MI5 has done”, to which the Queen replied “and very successfully too”.

She was also shown a Nazi Iron Cross awarded to “Garbo” described as the greatest double agent of the Second World War, for his work in tricking German high command over the D-Day landings.

Queen Elizabeth II gave a speech at the HQ. (Press Association)

Queen Elizabeth II talks with MI5 officers who were not allowed to be named. (Press Association)

His real name was Juan Pujol and he fed misinformation to Nazis from a fictitious group of informants, which left Adolf Hitler’s senior officers thinking they were getting important landing information.

Story continues

Sir Andrew said: “Because they so believed the intelligence they were receiving, he was decorated for it; in reality he was deceiving them and saved many lives at Normandy.”

She was also told about the work of her father, King George VI, who deceived the enemy by visiting a fake oil storage depot in Dover built by Shepperton film studios on behalf of the War Office.

The visit comes after the government had to deny claims that MI5 chiefs don’t trust Home Secretary Priti Patel and have been limiting intelligence sharing.

Queen Elizabeth II with Director General Andrew Parker at her first public visit. (Press Association)

Read more: Prince Charles visits flood-hit town in South Wales

MI5’s work now focuses on Islamist extremism, Northern Ireland-related terrorism and hostile foreign state activities as well as right-wing terrorism.

At any one point there could be 600 investigations underway about up to 3,000 individuals.

The Queen met a range of staff at the head quarters, and spoke to one who manages MI5 officers as they recruit members of the public to provide intelligence on terrorist threats.

Queen Elizabeth II paid tribute to the way the staff adapt to changing threats. (Press Association)

The manager, who cannot be named, said: “I told the Queen we rely on the bravery of the members of the public. They do extraordinary things on our behalf.”

Sir Andrew gave a speech and praised the Queen, telling her: “Your powerful sense of duty and public service to the nation has been an inspiration to us.

“For more than a century MI5 has undertaken vital work to keep the country safe. Your Majesty’s support for the work we do is appreciated by us all.”

Queen Elizabeth II talks to Director General Andrew Parker outside MI5. (Press Association)

Last year, the Queen’s grandson Prince William spent three weeks at MI6, MI5 and GCHQ, spending a week with each agency in what he called a “truly humbling experience”.

After the three weeks, he said: “These agencies are full of people from everyday backgrounds doing the most extraordinary work to keep us safe. They work in secret, often not even able to tell their family and friends about the work they do or the stresses they face. They are driven by an unrivalled patriotism and dedication to upholding the values of this country.

“We all owe them deep gratitude for the difficult and dangerous work they do.”

Watch the latest Royal Story videos from Yahoo UK