David Rein, 65, a Washington lawyer for 40 years who was noted for his work on behalf of civil liberties and civil rights, died at Sibley Memorial Hospital Saturday following a heart attack. He was stricken while playing tennis in Washington.

Mr. Rein began a private practice in Washington in 1946 with Joseph Forer. Their firm soon established a reputation for representing unpopular causes, and in many of them Mr. Rein prevailed.

During the early years of the Cold War in the late 1940s and early 1950s, Mr. Rein represented more than 100 persons who had been termed "unfriendly" witnesses by the House Committee on Un-American Activities, the Senate Internal Security Subcommittee of the Senate subcommittee headed by the late senator Joseph McCarthy (R-Wis.).

When a number of these witnesses were indicted for contempt of Congress, Mr. Rein won acquittals for them either in the trial courts or on subsequent appeals. His last such case involved leaders of the Women's Strike for Peace, who were charged with contempt by the House Committee on Un-American Activities.

In the 1940s and 1950s, Mr. Rein was counsel for the Coordinating Committee for the Enforcement of the D.C. Anti-Segregation Laws. The committee brought a suit seeking to desegregate a restaurant on the grounds that the business's policies, which were widely practiced in Washington at the time, were in violation of laws passed in 1872 and 1873.

The case went to the U.S. Supreme Court, which ruled in favor of the committee. The segregation policies in the city's restaurants, theaters and other places of public accommodation were thereby ruled illegal.

Other cases that Mr. Rein argued before the Supreme Court concerned the rights of striking workers, the foreign born and servicemen. In one of these cases, the government was limited in its right to deport aliens who had former leftist affiliations. In another, the National Council for American-Soviet Friendship won the right to contest in court its designation by the attorney general as a "subversive organization."

Mr. Rein also represented pressmen who went on strike against The Washington Post in 1975.

He and Mr. Forer continued their firm until July 1978, when Mr. Forer retired. Mr. Rein then became a partner in the firm of Rein, Garfinkle and Dranitzke. He remained active in it until his death.

Mr. Rein was born in New York City. He graduated from Columbia University and then earned a law degree there.

He subsequently worked for the Puerto Rican Reconstruction Administration, the National Labor Relations Board and the Office of Price Administration.

In World War II, he enlisted in the Marine Corps and saw action in the Pacific. He held the rank of first lieutenant when he left the service.

Mr. Rein belonged to the D.C. chapter of the National Lawyers Guild and was a member of its executive board.

Survivors include his wife, Selma, of the home in Washington; a son, Richard, of Reston; a brother, Louis, and a sister, Edith Besso, both of Margate, Fla., and two grandchildren.