The Duke of Cambridge has spent a "humbling" three weeks working with MI5, MI6 and GCHQ, to better understand how the UK's security and intelligence agencies work.
His time came to an end at the weekend, when he spent the final day of his attachment at GCHQ in Cheltenham.
The services are "full of people from everyday backgrounds doing the most extraordinary work to keep us safe," William said.
The head of counter-terrorism at GCHQ said the Duke had worked "exceptionally hard" on his placements.
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.
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.