LONDON — Prince William, Britain's second in line to the throne, enjoyed a brief stint with the U.K.'s security and intelligence agencies last month.

The Duke of Cambridge spent three weeks embedded with MI5, MI6 and GCHQ, agencies responsible for domestic and foreign security, to see how they operate first-hand.

“Spending time inside our security and intelligence agencies, understanding more about the vital contribution they make to our national security, was a truly humbling experience," William said in a statement released by the royal family late Saturday.

"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," the royal said.

The Sunday Telegraph newspaper reported that the father-of-three — who previously trained as a helicopter pilot with the Royal Air Force — worked with analysts and investigators monitoring Islamist terror cells and is understood to have worked actively in the field as well as in the office.

The prince's assignment began with a week at MI6, whose agents collect foreign intelligence and mount operations overseas, according to the statement. The agency was made famous by the James Bond series of novels and films.

His second week was spent at MI5, Britain's domestic counter-intelligence and security agency.

The Duke spent his last assignment at the Government Communications Headquarters (GCHQ), an agency that tackles terrorism, organized crime and cyber security.

Officials said the prince completed his final day of his work placement at GCHQ on Saturday.

We hosted the Duke of Cambridge this week at a number of our sites. The Duke learned about our vital mission to protect the UK and saw how we use cutting-edge technology, technical ingenuity and wide-ranging partnerships to identify, analyse and disrupt threats@KensingtonRoyal pic.twitter.com/2UkG0IfmVj — GCHQ (@GCHQ) April 7, 2019

The current threat of terrorism in the U.K. remains 'severe' — meaning an attack is highly likely.

The Head of Counter-Terrorism Operations at GCHQ, who remained anonymous, said the prince "worked exceptionally hard to embed himself in the team and comfortably held his own among some highly skilled analysts and operators."

"His Royal Highness asked some probing questions and demonstrated a real grasp of our mission," they added.

William will visit New Zealand this month on behalf of his 92-year-old grandmother Queen Elizabeth, the country's head of state, to honor the 50 victims of the mass shooting at mosques two weeks ago.