Mayor Marion Barry said yesterday that it was the press, not U.S. Attorney Joseph E. diGenova, that attempted to ruin his political career by linking him to the activities of convicted cocaine dealer Karen K. Johnson.

Although he accused diGenova's office last summer of attempting to "lynch" him with damaging leaks from the investigation, Barry said yesterday he had been hasty in making that charge and now believes it was the media that tried to damage him.

"The media in their zeal and zest for sensational headlines have attempted to try me not by a jury of my peers but rumor, innuendos, encouragement of leaks and violating secrets of the grand jury," Barry said. "It is frightening that one's reputation can potentially be destroyed by such tactics."

Barry called a news conference several hours after diGenova announced the end to a two-year federal investigation of drug use by D.C. employes. The mayor acknowledged that he had known Johnson through late 1982 and visited her occasionally at her 16th Street NW apartment, but denied that he ever bought cocaine from her or used it.

When asked what he and Johnson did during those visits, the mayor replied: "I had a sip of cognac . . . and tea and coffee and milk and orange juice and champagne."

The mayor also left open the possibility that Johnson, a former D.C. Energy Office employe who yesterday completed an eight-month sentence for refusing to testify before the grand jury, may resume working for the city while she serves out another four-month sentence for her conviction on charges of selling and possessing cocaine.

Johnson, 33, a former Barry campaign worker, was transferred yesterday from the D.C. Jail to a minimum security federal corrections center in Southeast Washington, where officials said she is required to hold an outside job.

Barry said that city lawyers who have reviewed Johnson's drug sentencing order said it appeared that U.S. District Judge Joyce Hens Green "wanted her to continue her work" with the city.

Johnson said in a conversation with a boyfriend -- secretly tape-recorded by federal agents -- that she had sold cocaine to the mayor on numerous occasions.

Barry denied that allegation when he testified before the grand jury in January 1984, according to sources, but Barry declined yesterday to discuss that testimony. Barry also repeatedly declined to say whether Johnson named him on the tape that he said was played for him when he appeared before the grand jury.

"A number of people's names came up on the tape , but I'm not going back to what happened in the grand jury," he said.

After Johnson refused to testify before the same grand jury, prosecutors stepped up their efforts to determine whether Barry had committed perjury in his testimony. However, they were unable to substantiate the allegations.

In a terse announcement yesterday, diGenova said: "A federal grand jury concluded, without further indictments, the investigation in which Karen K. Johnson had been subpoenaed as a witness."

Barry said he would have preferred that Johnson had testified, to clear up any questions about his involvement. He added that Johnson showed "courage and resolve to say no to the judge" when she was ordered to testify or go to jail for contempt.

"To tell the truth would have helped me," Barry said. "Why she chose not to talk to the grand jury is something you'll have to ask her.

"There is some view that her not talking was involving me," he added. "I will maintain . . . that part of their prosecutors' frustration is that they did not find out the sources of the drugs" sold by Johnson.

Barry said that he hoped diGenova's announcement would put an end once and for all to reports and speculation about his involvement in the drug investigation.

"Fortunately in my case, the citizens of the District of Columbia knew of my deep commitment to people and my compassion for those less fortunate among us, my personal zeal for excellence and my unblemished record of integrity," Barry said. "Therefore they stood with me and by me. This includes my wife Effi."

The mayor was joined at the press conference by his legal counsel, Herbert O. Reid Sr., who has advised Barry throughout the drug investigation and who told The Washington Post last August that Barry had had a "personal relationship" with Johnson and occasionally visited her apartment.

Reid said at the time that the relationship lasted 12 to 18 months and ended in the fall of 1982. Johnson admitted to selling cocaine during much of the time Barry was visiting her.

"I have never been around her when she either used or sold drugs," Barry said yesterday. The mayor also said he had nothing to do with Johnson's getting her D.C. government job.

Johnson, a California native and the mother of a small child, has told friends that she was introduced to Barry some time in 1981 at a fund-raiser at a downtown Washington night spot. Later that same year, she was hired as an energy conservation specialist in the D.C. Office of Energy, where she was earning $22,217 a year when she was indicted in April 1984.

Barry and Reid have described Barry's relationship with Johnson differently. In April 1984, on the day Johnson was indicted, Barry told a reporter that he "vaguely" knew Johnson. That August, Reid told reporters that it was a "personal" relationship. On later occasions, Barry described the relationship as "social," and when asked if he had had an affair with Johnson, said, "Of course not."

Barry, who spoke with diGenova before the press conference, sought to play down his earlier sharp criticisms of the prosecutor. At the height of the controversy over the drug investigation last summer, Reid wrote a letter urging then-attorney general William French Smith to appoint a special prosecutor to determine if diGenova had been involved in "illegally leaking information" about the investigation.

Yesterday, when asked about diGenova, Barry said: "I'm more concerned about what you all [the media] did than what he did."