John William McCormack, 88, a Massachusetts Democrat who was speaker of the House of Representatives from 1961 to 1971 and served in the House for 42 years, died Saturday in a nursing home in Dedham, Mass. He had pneumonia.

Mr. McCormack had presided over the House during an extrordinary period when Congress enacted landmark legislation in the fields of civil rights, education, health care for the elderly and welfare to end poverty. But toward the end, the expense and bitterness of the Vietnam war slowed domestic progress.

President Jimmy Carter said yesterday that he was saddened to learn of Mr. McCormack's death and said he was a "man of strong character and a distinguished speaker of the House, who served with distinction and a strong, heartfelt belief in the Democratic Party."

The current House speaker Thomas P. (Tip) O'Neill Jr. (D-Mass.), said, "We have lost a great American. I have lost a close friend and political mentor of 40 years."

Massachusetts Gov. Edward King said, "John McCormack was integrity and character personified. He was an outstanding example of everything our faith and country stand for. Knowing him even just a little assures remembering him always."

Mr. McCormack was peculiarly a product of turn-of-the-century South Boston, across the tracks from the Kennedy home.

Most of the neighbors were poor, Irish and Catholic; the politics, flamboyant, personal and Democratic. He grew up in the "Last Hurrah" atmosphere of tenement wards where wakes, St. Patrick's Day parades and a florid oratorical style were important.

He studied law at night, went off to Congress and rose to the second most powerful elected office in the land as Speaker of the House. His constituants could never complain that he put on airs. He always spoke the language of a Boston man who did not go to Harvard, and when home he usually could be found visiting sick rooms or political clubs.

John McCormack was many things that his predecessor, Sam Rayburn of Texas, was not. He was tall, thin, silver-haired, a teetotaling Irishman who liked to wheel and deal with an arm around the shoulder. He maintained warm ties with some Southerners whom Rayburn could never budge, but he never quite mastered Rayburn's knack of making the House behave.

Born Dec. 21, 1981, the son of a hod carrier, Mr. McCormack quit school after the eighth grade to help support his widowed mother and family as a $3-a-week errand boy for a brokerage firm. His career began when he shifted to a law firm for a 50-cent raise and studied law on the side. He made a name as a Boston trial lawyer, moved through the chairs in the state legislature and went to Congress in 1928.

Mr. McCormack moved up fast in the House, thanks to Speaker John Nance Garner, who put him on the powerful Ways and Means Committee in his second term. He made his mark as a New Deal supporter and his voting record was unwaveringly liberal throughout his career.

During the mid-30s he served as chairman of the forerunner of the Un-American Activities Committee and ran a quiet investigation of Fascist and Communist subversion.

When Rayburn became House speaker in 1940, Mr. McCormack followed him into the floor leader's chair and served for 21 years as second-ranking Democrat in the House until Rayburn's death, after the end of the 1961 session.

During his days as floor leader, Mr. McCormack was a belligerant Democrat. He was usually on the floor during a session, slumped in a front row seat holding a dead cigar, ready to leap into debate with a partisan bite. His method of urging bi-partisan support was to yell across at Republicans that President Eisenhower would never have got anything done without Democratic help. He usually irritated someone.

Mr. McCormack's transformation in manner as speaker was remarkable. As presiding officer of the House, he was impeccably fair and impartial, never ignoring an obstreperous member seeking recognition to make a troublesome point of order. His rare floor speeches usually were restrained. His demeanor generally was that of a kindly elder relative with an unruly brood.

A member who had watched Mr. McCormack for years said his strength was his personal consideration of members, which inspired in return affection and a desire to help; his weakness, that he couldn't control the powerful committee chairmen who hold most of the power in the House.

Mr. McCormack probably will not be remembered as one of the strong speakers in the rank of Rayburn, Cannon and Reed. His long service as second to Rayburn was like being Number Two man in a one-man operation. With Rayburn gone, it became apparent that the speaker had little institutional power beyond the force of his own personality, and cries for basic reform grew louder.

Mr. McCormack undeniably had his troubles.The House met all year in 1963 without finishing its work, and wound up sitting through one futile all-night session, finally passing the last bill at a 7 a.m. session.

The House Appropriations Committee conducted an unseemly squabble with the Senate all through 1962 over where to meet, and Appropriations Committee Chairman Clarence Cannon (D-Mo.) closed the session with a speech blasting the House leadership as the worst he had seen in 40 years.

Mr. McCormack could properly claim that he was a "national" congressman. He fought for farm bills, even though he said he hadn't "more than five flower pots in my whole district."

On a close vote on a cotton bill, the speaker could be sweeping members from the lobbies onto the floor, the job of an assistant whip. He played a key role in extending the military draft just before Pearl Harbor when to many it was still England's war. He was an early fighter for civil rights legislation.

His personal kindnesses were legion, and if he harbored vindictiveness it was hard to see. Pundits predicted foot-dragging by the speaker after President Kennedy's 30-year-old brother won a Massachusetts Senate seat from McCormack's favorite nephew, the highest Democratic officeholder in the state and a logical candidate. The speaker never showed by word or deed that he bore a grudge.

Although his basic views were shaped in the past -- the New Deal and staunch anticommunism firmed the foundations -- he presided over a period of gradual but definite change in the House. He didn't sympathize with the antiwar demonostrations, but he bent the rules to let the long-haired youths express their views on the Capitol steps.

Mr. McCormack used to speak of New Deal triumphs and the war against Hitler to young members and students who could not remember them. He was a staunch anti-Communist crusader and seemed to equate the war against communism in Vietnam with the war against Nazism in Europe.

He went along, if not enthusiastically, with some reforms, such as making the House take its important votes on the record and taking the first tentative swipe at the seniority system.

Away from the House, the speaker sank out of public view in Washington. He lived quietly at the Washington Hotel with his wife. Their devotion was a Washington legend. It was said that they had never spent a night apart in more than 52 years of marriage. If the speaker was kept late at the Capitol, Mrs. McCormack always went up to have dinner with them. They had no children.

In December 1971, the 52-year love affair between Harriet and John McCormack ended when she died at Providence Hospital here at the age of 87. For more than a year, he had spent every night in an adjoining hospital room. Then at 80, Mr. McCormack went home to Boston.

Mr. McCormack had few hobbies except politics. In earlier days, he was known as a good high stakes poker player. He never flew in an airplane until 1961, when he attended Rayburn's funeral. He drove the 450 miles from Washington to Boston or went up on the night sleeper train.

The speaker and his wife were devout Catholics. Both were honored by the Vatican. He was the first Catholic to be elected speaker, and some critics complained that this religion sometimes showed in his leadership qualities.

An example cited was the 1961 school aid debacle when Mr. McCormack insisted that church schools should share in a federal aid program. The bill died on this issue. But in 1963 Mr. McCormack helped push through the largest education program in history, much of which went to public institutions only.

In 1970, the sniping by young liberals at Mr. McCormack increased and several congressmen urged him to step down because he was too old. One Congressman asked a party caucus to declare a lack of confidence in his leadership. It did not.

Mr. McCormack left the House like a good poker player, his decision a secret from his closest friends there.