Lord "Rab" Butler, 79, an intellectual politician who was instrumental in reviving Britain's postwar Conservative Party and making it a partner in the development of the welfare state, died last night at his home near London. He had a heart ailment.

Lord Butler, often described as "the best prime minister Britain never had," served in every other top post in government--chancellor of the exchequer, foreign secretary, home secretary and deputy prime minister--but was twice denied the opportunity to become prime minister.

A tall, urbane man with a round, kindly face that disguised his sly wit and sharp intellect, he was credited with rescuing the Conservatives from their 1945 landslide defeat by the Labor Party and its reputation as the unfeeling party of the aristocracy. As chairman of the party's postwar planning committee and as chancellor of the exchequer and home secretary, he stressed compassionate policies, compromise with Labor, and pragmatism.

This linked his name with that of former Labor leader Hugh Gaitskell in the term used to describe the resulting British political philosophy of the middle way: "Butskellism."

Acknowledging the timidity that some said lost him his last chance to be prime minister when Conservative Party elders turned instead to Sir Alec Douglas-Home after Harold MacMillan's resignation in 1963, Lord Butler later said, "I ought to have pushed more and got it for myself."

In 1965, after 35 years in politics, he accepted from Labor Prime Minister Harold Wilson a life peerage and appointment as master of Trinity College of Cambridge University. His last public service during his 13 years there was to serve as a close adviser to Prince Charles, heir to the British throne, when he was a Cambridge student from 1967 until 1970.

Prime Minister Margaret Thatcher today called Butler "one of the greatest men and most distinguished personalities of this century . . . a true scholar and a true patriot."

Foreign secretary Lord Carrington, who worked as Butler's deputy in the foreign office, said "he was a giant among politicians of the postwar years. He was a man of enormous intelligence and political skill and there was a flavor about him almost impossible to describe."

"For my generation," said former Conservative prime minister Edward Heath, "he was the man who created the modern, moderate Conservative Party." Lord Home called him "the philosopher" of the party.

Richard Austen Butler (his nickname came from his monogram) was born in India, where his father and uncle were both provincial governors, and was graduated with honors from Cambridge University.

He was first elected to the House of Commons in 1929 and rose quickly to ministerial postions in the India office, the ministery of labor and the foreign office. He earned the sobriquet "Stone-wall Butler" for cool evasions of parliamentary questions about the Neville Chamberlain government's policy during its appeasement of Hitler and Mussolini.

But Winston Churchill kept Lord Butler in government, later moving him to education, where Butler developed the landmark 1944 education act that reorganized British secondary education into the system whose framework remains in place today. "One of his greatest achievements was the Education Act of 1944, which gave every child a statutory right to free secondary education," said Thatcher, herself a former education minister.

Lord Butler's refusal to give full support to Anthony Eden's invasion of the Sinai peninsula over Suez was believed to have caused the party elders to pass over him and choose MacMillan instead as Eden's successor as party leader and prime minister.

When the chance came again after MacMillan's resignation in 1963, wrote Butler's biographer, Patrick Cosgrave, he "spoke to anybody who wanted to speak to him, affirmed that he very much wanted to be prime minister, and admitted that he thought himself by far the best candidate. But he did not try to urge people on . . . "

Lord Butler's first wife, Sydney, died in 1954. They had three sons and a daughter. He is survived by the four children and by his second wife, the former Mollie Courtauld, whom he married in 1959.