Prince William works with security agencies on attachment
GCHQ’s head of counter-terrorism said the duke worked “exceptionally hard”.
The royal learned about risks to the UK’s national security and economy, Kensington Palace said.
He also observed counter-terrorism teams analysing intelligence and carrying out investigations.
The prince’s attachments came to an end on Saturday.
Prince William’s attachment comes after the Queen celebrated GCHQ’s centenary earlier this year with a visit to its former top secret base, Watergate House in London.
The threat to the UK from international terrorism is currently classed as severe, which means a terror attack is “highly likely”.
The head of MI6 warned in February the Islamic State group was preparing for more attacks, despite its military defeat in Syria.
And in January, the former head of MI5, Baroness Manningham-Buller, warned leaving the European Union without a deal would make the UK “less safe”.