Four British prime ministers as well as Buckingham Palace knew that the queen's art curator, Anthony Blunt, was a Soviet spy who had secretly been granted immunity from prosecution in return for his confession and information about Soviet intelligence operations here.

But Sir Alec Douglas-Home, the prime minister at the time the immunity deal was made in 1964, was not consulted or informed, and no one will disclose whether the queen was told.

These details about the Blunt affair emerged in a special parliamentary debate tonight, in which three prime ministers -- Margaret Thatcher and predecessors James Callaghan and Edward Heath -- defended the secret deal with Blunt as the only way to extract from him what Heath called "a great deal of valuable information."

Without consulting Sir Alec, who has since become Lord Home, his attorney general and home secretary approved the immunity offer. They did so after investigators had failed 11 times in the previous eight years to convince Blunt to confess, Thatcher and her Attorney General, Sir Michael Havers, told the House of Commons tonight.

When officials went to Blunt's Home in April 1964 to question him for the 12th time, Havers said, they revealed new information implicating him. But Blunt repeated his previous denials.

When they then offered him secret immunity from prosecution, Havers said, Blunt first fell silent. "He got up," the attorney general told his hushed audience, "looked out the window, poured himself a drink, and after a few drinks, confessed.

"He later cooperated and continued to cooperate with the security services," Havers told the Commons. "In my view, these events clearly justified the decision" to give Blunt secret immunity and allow him to continue in his work for the queen, who had knighted him in 1956 for his personal service to her.

Thatcher said that after the decision to grant Blunt immunity first was made in 1964, the queen's private secretary was summoned to a meeting with security officials and told about it.

"The queen's private secretary asked what action the queen was advised to take if Blunt confessed," Thatcher told the House of Commons tonight. "He was told that the queen should take no action. Any action would have alerted Blunt's Russian controllers, and others who were already under suspicion, to the fact that he had confessed and may have been providing information to our security authorities."

"The palace duly followed this advice," Thatcher added without further elaboration. Havers and Buckingham Palce spokesman later emphasized that communications between the queen and her private secretary are private.

Thatcher and Havers, along with several previous prime ministers and attorneys general who spoke in the extraordinary debate, said that Blunt could not in fact have been prosecuted. Independent evidence implicating him was not nearly sufficient for a conviction, they explained, and his confession would have been inadmissionible in court because it was obtained by giving him immunity.

Havers said it was the only time a suspected spy had been given immunity from prosecution since World War II, although persons in some other espionage cases were offered "inducements which might have redered any statements made as a result of the inducement inadmissible in any subsequent criminal proceedings."

There were hints from several officials that information from Blunt had unmasked other Soviet agents inside the British government. Thatcher said that after "thorough investigations" of the spy ring of Blunt and his friends Guy Burgess, Donald Maclean and Kim Philby, "a number of people left the public service or were transferred to work which did not involve access to classified information. I am satisfied that all appropriate steps were taken to safeguard national security."

As Thatcher spoke, she was watched by a total of four former prime ministers whose tenures overlapped the Blunt case -- Callaghan, Heath and Harold Wilson from the the floor of the oak paneled House of Commons, and Lord Home from the Peer's Gallery above.

Heath and Callaghan advised against holding a formal inquiry to the Blunt case or setting up a parliamentary committee to oversell Britian's intelligence agencies. Heath said that could harm the morale and secrecy needed by those agencies. He added that "what has happened to the American security services causes the greatest anxiety in the whole Western world."

Callaghan added, however, that he thought it was "wrong" to advise Buckingham Palace to keep Blunt in the queen's service.

"I'm bound to say that I think there has been a tendency to treat Blunt with kid gloves," Callaghan said, "and I made this clear when I was prime minister."