Prince William has concluded a three-week attachment with the UK security and intelligence agencies MI5, MI6 and GCHQ, his office says.
William started his assignment at the Secret Intelligence Service, known as MI6, followed by a week at security service MI5, ending at GCHQ, which gathers communications from around the world to identify and disrupt threats to Britain.
William first spent a week with the Secret Intelligence Service, also known as MI6, which deals with foreign intelligence and protects the UK from risks abroad.
He learned about the risks to the UK's national security, military effectiveness and economy, Kensington Palace said.
He then shadowed the Security Service (MI5) for a week, where he saw counter-terrorism teams analysing intelligence and conducting investigations on UK soil.
- Prince William to visit Christchurch after terror attack
- John Key reveals he helped Prince William slip security
Finally, he worked at GCHQ, the Government's listening centre in Cheltenham, Gloucestershire, which monitors communications to look for potential security threats to the UK.
"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," said William.
"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."