Thomas P. "Tip" O'Neill Jr., a Massachusetts Democrat who during his 10 years as speaker of the House of Representatives became one of the nation's best-liked, widely known and most influential leaders, died last night in Boston.

Mr. O'Neill, 81, died at 9:43 p.m. at Brigham and Women's Hospital of cardiac arrest, his family said in a statement from the hospital.

Mr. O'Neill was the quintessential urban ethnic politician. He held elective office for 50 years, including 16 years in the Massachusetts legislature and 34 years in the House. He based his career on the maxim, "all politics is local," and his rise to power rested primarily on personal relationships, party loyalty and favors that he did for constituents and colleagues.

When he retired as speaker in 1986, he had held that office for a longer continuous period than any other.

"Mr. O'Neill was a great American who served his country with distinction for many decades. He leaves behind a grand legacy of public service," the White House said in a statement last night.

Mr. O'Neill's last six years as speaker coincided with the presidency of Ronald Reagan, and they came at a time when the Republicans also controlled the Senate. Thus, Mr. O'Neill was the highest-ranking Democrat to hold national office during that period.

He was sometimes called the core of the Democratic Party, and he drew wide media exposure as his party's most vocal spokesman and the president's most effective and formidable opponent. Mr. O'Neill, with his shock of white hair, his perpetually rumpled shirt, bulbous nose and generous waistline, was a familiar figure to millions of Americans.

It was once said that he "wears the speakership like a glove." His reputation was that of a brilliant and cunning political strategist with an uncanny sense of timing who always seemed to know when to compromise and when to hold out for more. He was most effective away from the limelight in the back rooms and corridors where the horse trading and arm twisting that determine the fate and form of legislation take place.

He was perhaps the most dominant figure in the House since the death of former speaker Sam Rayburn (D-Tex.) in 1961 but, because of changes in various House procedures and rules, he was unable to exercise the kind of absolute power that Rayburn did.

What Mr. O'Neill did have was a warm and outgoing personality. He was a superb story-teller who loved to sit in the back of his office and spin yarns. In the early 1980s, the Republicans tried to make him the butt of a series of television advertisements featuring an actor look-alike, but the strategy backfired, and instead he became a symbol of national affection. Many representatives voted with Mr. O'Neill simply because they liked him.

As speaker, he presided over a fractious and diverse body of men and women, including many new members who came to Congress in the reform-minded post-Watergate era. They tended to have a low regard for party discipline and the traditions of the House, and they were not easily manipulated.

Nevertheless, under Mr. O'Neill's leadership, the House passed landmark legislation such as a wide-ranging ethics code governing the behavior of its members, Reagan's comprehensive tax reform package and President Jimmy Carter's omnibus energy bill. It restored proposed cuts in Social Security benefits and passed other social welfare programs, and it voted to terminate covert aid to rebel forces in Nicaragua.

Some in the House criticized Mr. O'Neill for being often unfamiliar with the details of legislation, but no one ever suggested he was less than a master of legislative mechanics.

House Republicans had this quickly demonstrated in January 1977, during the first hour of Mr. O'Neill's speakership. In less than 60 minutes, Mr. O'Neill pushed through more than two dozen rules changes aimed at weakening the power of the 143-member Republican minority. Those changes restricted the use of quorum calls and other delaying tactics that historically have been the minority's primary legislative weapons.

In his personal life, Mr. O'Neill liked baseball, beer, cigars and card playing. He always seemed to be trying to lose weight, and he once remarked that over the years he had probably lost -- and regained -- more than 1,000 pounds. He often was described as looking like the man next door in the working-class neighborhood of his native North Cambridge, Mass., where he lived most of his life. The Boston Globe observed that a primary reason for his political success was that he "kept the same wife, the same friends, the same lifestyle, the same values and the same philosophy that he began with in the '30s."

He believed deeply that it was the government's responsibility to improve quality of life for the ordinary person, and he kept a framed copy in his office of the Hubert H. Humphrey quotation, "The moral test of government is how it treats those who are in the dawn of life, the children; those who are in the twilight of life, the aged; and those who are in the shadows of life, the sick, the needy and the handicapped."

Those beliefs evolved from his early life experiences as the child of Irish parents in Boston at a time when the barons of commerce and industry accompanied their help-wanted notices with signs advising that "No Irish Need Apply."

Mr. O'Neill's mother died of tuberculosis when he was 9 months old, and during his early childhood the nuns from the Roman Catholic parish in his neighborhood helped to look after him. He was nicknamed "Tip" after St. Louis Browns baseball player Edward O'Neill, who became so adept at hitting foul tips that opposing pitchers ended up walking him.

His father was a union bricklayer who later became a Cambridge city councilman and superintendent of sewers.

Mr. O'Neill lost the first election he entered -- a bid for a seat on the Cambridge City Council, while he was still a Boston College student. But he learned something in the process from a friend and former teacher named Mrs. O'Brien, whose vote he had not bothered to solicit because he assumed he would get it.

"People like to be asked," she told him.

"She gave me the lesson of my life," Mr. O'Neill observed more than 50 years later in his autobiography, "Man of the House." In subsequent elections he always asked his wife to vote for him just as they left home for the polls. Her answer was always the same. "I'll give it every consideration."

In 1936, at age 24, Mr. O'Neill won a seat in the Massachusetts legislature, the first of 25 consecutive biennial elections he would win before his 1986 retirement.

In 1948, he helped orchestrate a statewide campaign that produced the first Democratic majority ever in the state's House of Representatives. Mr. O'Neill subsequently became that body's first Democratic speaker.

He held that job for four years, until 1952, when he was elected to the seat in the U.S. House of Representatives that was vacated by John F. Kennedy to run for the Senate against Henry Cabot Lodge.

As a first-term representative, Mr. O'Neill came under the tutelage of the Democratic majority leader in the House, fellow Bostonian John W. McCormack, who saw to it that he got to know Speaker Rayburn. Rayburn later assigned him a seat on the Rules Committee that controls the flow of legislation to the House floor. In that assignment Mr. O'Neill acquired a detailed and intimate knowledge of how the House operated, and he got to know more of its members than most of his colleagues.

Until he became speaker in 1977, his wife and family remained in Massachusetts, and Mr. O'Neill commuted home on weekends.

As a staunch party loyalist, he voted with the Democratic leadership most of the time, but on occasion he did break rank. He came out against Lyndon B. Johnson's conduct of the war in Vietnam in 1967, one of the first of the Establishment Democrats to do so.

In 1970, he replaced Ohio's Mike Kirwan as chairman of the Democratic Congressional Campaign Committee, which raises and distributes campaign funds for House Democrats, and became Democratic Party whip in 1971, when Carl Albert succeeded McCormack as speaker and Hale Boggs of Louisiana became majority leader.

On a flight to Alaska in October 1972, Boggs's plane was lost in a rainstorm between Juneau and Anchorage. The following January, Mr. O'Neill became majority leader. He was elected speaker without Democratic opposition after Albert retired in 1976.

His first four years as speaker coincided with the presidency of Carter. But Carter's staff, in Mr. O'Neill's view, gave short shrift to its relations with Congress and the relationship between the president and the speaker was never close.

The nadir of his speakership came during the first year of the Reagan presidency, when the White House pushed through some of the largest increases in defense spending in the nation's history, while sharply curtailing domestic programs and cutting taxes, all over Mr. O'Neill's opposition.

"For a while, I was a solitary voice crying in the wilderness," Mr. O'Neill recalled in his autobiography. At one point he faced a rebellion in his own ranks, but events began to turn in Mr. O'Neill's favor in mid-1982. The Democrats gained 26 House seats in congressional elections that fall, partly by attacking the Republicans for Reagan's cuts in antipoverty and education programs and in Social Security benefits. When the House reconvened in January 1983, the rebellion against Mr. O'Neill had dissipated.

During the remaining years of his speakership, Mr. O'Neill clashed repeatedly with Reagan, referring to his presidency as being "of the rich, by the rich and for the rich." But the two men remained on good terms personally, and the president had warm praise for Mr. O'Neill at a 1986 dinner saluting the speaker on his 50th anniversary in politics.

On June 17, 1941, Mr. O'Neill married the former Mildred Ann Miller. They had five children, Thomas P. III, Christopher, Michael Tolan, Susan and Rosemary.