Did Agatha Christie have a spy in the government's top-secret codebreaking centre at Bletchley Park?

That was the fear of intelligence chiefs at MI5 during the second world war who were so concerned that they decided to investigate her contacts.

What made MI5 suspect one of Britain's famous crime writers? The answer, it can now be revealed, lay in the name of a character in her wartime novel N or M, whom she called Major Bletchley. He appears in the book as a friend of Christie's pair of detectives, Tommy and Tuppence.

In the book, published in 1941, N and M are the initials given to two of Hitler's agents as Tommy and Tuppence hunt for the enemy within. Major Bletchley comes across as a tedious former Indian army officer who claims to know the secrets of Britain's wartime efforts.

Christie happened to be a close friend of Dilly Knox, one of the leading codebreakers at Bletchley Park. MI5 was concerned that the major's inside knowledge of the progress of the war was based on what the codebreakers knew about Hitler's plans. Had Christie mischievously named the character Bletchley because Knox told her what was going on there?

The codebreakers at Bletchley Park in Buckinghamshire had broken German Enigma machine cyphers, enabling Churchill and his military commanders to know what the enemy was planning. Berlin believed Enigma was unbreakable, making it all the more essential to ensure that only a very small circle of people knew what the codebreakers at Bletchley were up to.

What worried MI5 even more was that it was Knox who had just broken the Enigma machine cypher used by German secret service officers sending spies to Britain.

According to a new account of the achievements of Bletchley Park – The Codebreakers of Station X, by Michael Smith, published on Monday by Shire books – MI5 was anxious to find out what Christie knew. It sent officers to question Knox, fearing that if they or the police questioned Christie the investigation was certain to be publicised.

Knox said Christie could not possibly know what was going on at Bletchley, but agreed to ask her himself. He realised he had to be careful exactly what he said to the author. He invited her to his home at Courn's Wood, Naphill in Buckinghamshire, and, according to friends of Knox, over tea and scones asked why she had named the Indian army major Bletchley.

Christie replied: "Bletchley? My dear, I was stuck there on my way by train from Oxford to London and took revenge by giving the name to one of my least lovable characters." MI5 was relieved.

Knox was dying of cancer when he broke the Enigma code used by German spymasters. He did not live to see how his discovery was a key factor behind the success of the "D-Day Double Cross" deception operation.

British military commanders deceived their German opposite numbers and knew that Berlin believed the allied landings would take place near Calais and not on the Normandy beaches.