It was one of the most anticipated book launches of all time and now it has emerged that Britain's spy agency had to intervene to make sure that the sixth Harry Potter novel was not spoiled for fans before its release.

Nigel Newton, founder of Bloomsbury Publishing, said that GCHQ contacted him in 2005 after apparently finding an early copy of Harry Potter and the Half Blood Prince online ahead of its official publication date.

However, after reading through the copy it was discovered to be a fake and the real book was kept under wraps until its official release.

The book had generated a lot of excitement among fans after author JK Rowling hinted that a key character could die in the book.

The secret intelligence agency, which is based in Gloucestershire, monitors electronic communications to prevent serious and organised crime, and terrorism.

Mr Newton told Australia's ABC Radio that it was vital to keep the plot a secret before the release.

He said: "If newspapers splashed 'Dumbledore dies' what pleasure is there going to be for a kid reading it? The enemies stood to ruin a great deal of pleasure for the world.

"We fortunately had many allies. GCHQ rang me up and said, 'We've detected an early copy of this book on the internet'. I got them to read a page to our editor and she said, 'No, that's a fake'. We also had judges and the police on our side.

"It was completely mad and we were at the eye of the storm - I remember Jo Rowling phoning me once after she had delivered a new book saying, 'please will you released the name of the title because I have people outside searching my trash cans looking for bits of paper."

Bloomsbury brought in extra security guards to patrol the presses ahead to try and stop the book being leaked before its release.

A GCHQ source told The I: "We don't comment comment on our defence against the dark arts."