WASHINGTON (AP) _ Roy Cohn, the flamboyant New York lawyer who catapulted to public prominence in the 1950s as the grand inquisitor of Sen. Joseph McCarthy's communist-hunting congressional panel, died Saturday at the age of 59.

Irene Haske, a spokeswoman at the National Institutes of Health, said the primary cause of Cohn's death at 6 a.m. EDT was cardio-pulmonary arrest, with ''dementia'' and ''underlying HTLV-III infections'' listed as secondary causes.

The HTLV-III virus is believed to cause AIDS, the fatal illness that most often strikes homosexuals and intravenous drug users. Cohn, a lifelong bachelor, repeatedly denied rumors that he suffered from acquired immune deficiency syndrome. He said he had liver cancer.

Ms. Haske refused to elaborate on Cohn's illness. She said she was only at liberty to release information recorded on the public death certificate.

Cohn, who was indicted three times during his controversy-filled career but was never convicted, died at NIH's Clinical Center in suburban Bethesda, Md., six weeks after he was disbarred in New York for financial misconduct.

The Appellate Division of the New York State Supreme Court said Cohn was guilty of dishonesty, fraud, deceit and misrepresentation.

One of the accusations upheld by the judges was that in 1976 Cohn went into the hospital room of a dying friend, whisky magnate Lewis Rosenstiel, and tricked him into signing over control of his multimillion-dollar estate. Cohn also allegedly improperly used money from clients' escrow funds.

Cohn said he was disbarred because ''the establishment bar hates my guts.'' He called his accusers ''a bunch of yo-yos'' out to smear him.

Last year he held off disbarment by pleading that he was terminally ill, but early in 1986 he appeared publicly to report that his liver cancer was in remission. He re-entered NIH for the second time in two years this summer.

Although he helped in President Reagan's 1980 election campaign and enjoyed access to the White House, Cohn was a registered Democrat with close friends in New York's Democratic circles.

A natty, well-groomed, perpetually suntanned bachelor, Cohn thrived on publicity and regularly showed up at ''in'' night spots, to be ushered to the best table while his peers waited behind a rope.

People he called his friends ranged from J. Edgar Hoover to Cardinal Terence Cooke, William F. Buckley and Barbara Walters.

Cohn paid himself a $100,000 annual salary, extremely modest for a lawyer at his level, but he lived like a millionaire by drawing on an expense account that in effect picked up the tab for his cars, homes and entertaining.

He said anything he owned would only be grabbed by the government, which had income tax liens against Cohn totaling $3,187,381 dating back more than 25 years, by the Internal Revenue Service's count.

The roster of Cohn's clients included Carmine Galante, the short-lived Mafia boss of bosses, and Anthony ''Fat Tony'' Salerno, alleged godfather of the Genovese mob; Peter Widener of the Philadelphia Wideners; fashion designer Halston and Andy Warhol, the pale eminence of pop culture.

''He's a real bastard and he'll bend the rules to the limit, but he's also smart as hell and you can't blame people who want him on their side,'' said a law professor who was quoted anonymously in a 1979 Newsweek article.

Cohn remained a darling of the anti-communist right all his life. He was remembered as the arrogant but brilliant 27-year-old inquisitor of McCarthy's Senate Permanent Subcommittee on Investigations.

''As a young man, he came to the conclusion that the Soviet Union and communism were a threat to the survival of the United States and freedom as we know it,'' said Thomas A. Bolan, Cohn's law partner for 29 years. ''He spent his entire public life fighting it.''

Bolan added that Cohn was ''a great friend, a man who went out of his way to help people. ...''

Liberals assailed Cohn and McCarthy, a Wisconsin Republican, for destroying the reputations and careers of people they tarred as communists or sympathizers through innuendo or guilt by association.

When he was indicted in the 1960s and early 1970s on charges including bribery, perjury, obstructing justice, mail fraud and extortion, Cohn complained that the prosecutors were really persecutors trying to settle old scores.

Cohn's major prosecutorial antagonists were Robert F. Kennedy, the attorney general who once was junior to Cohn on the McCarthy panel, and Robert Morgenthau, a former federal prosecutor and now Manhattan district attorney.

Cohn claimed Morgenthau wanted to get even for Cohn's having said there was subversion in the Treasury Deparment when Morgenthau's father was treasury secretary.

Roy Marcus Cohn was born Feb. 20, 1927, the only child of a state appeals court judge. He attended the Fieldston School in Riverdale, N.Y., and Columbia University, sailing through Columbia Law School by age 20.

While waiting to turn 21 so he could be admitted to the bar, Cohn worked as a clerk in the U.S. attorney's office, where he helped prepare and later prosecute the case against atom bomb spies Julius and Ethel Rosenberg.

He quit the Justice Department in 1953 to join McCarthy and soon hooked up with G. David Schine, a 26-year-old heir to a hotel fortune who worked for the subcommittee as an unpaid consultant. Their friendship eventually led to McCarthy's downfall.

Schine and Cohn went to Europe in the spring on an 18-day hunt for subversion on the shelves of U.S. Information Agency libraries in Europe, drawing ridicule from the foreign press but demoralizing agency staffers.

Schine was drafted into the Army that winter. When Cohn tried and failed to get special privileges for Schine, he allegedly threatened to wreck the Army with an investigation.

Badgering the Army put McCarthy on a collision course with the Eisenhower administration. The upshot was an independent investigation, the Army-McCarthy hearings of 1954.

During the ensuing, month-long Senate extravaganza, Army counsel Joseph N. Welch became a popular hero. McCarthy came across on television as a fulminating demagogue and never recovered.

In 1981, Cohn wrote ''How to Stand Up for Your Rights and Win,'' a do-it- yourself law book. He dedicated it to Welch, who he said gave him invaluable trial training as his adversary at the hearings.

''Some people think I'm pulling a grandstand play,'' he said of the dedication. ''On the contrary, I'm being very sincere.''

Cohn quit Washington and embarked on a lucrative private practice in July 1954.

Besides practicing law, Cohn was involved in a number of business deals. He once took over and then lost the Lionel Corp., the toy train manufacturer founded by his great-uncle, Joshua Lionel Cowen.

Funeral services will be private, but a memorial service will be held in September, said Bolan, Cohn's law partner at Saxe, Bacon and Bolan in New York.