D.C. Mayor Marion Barry apologized yesterday for a remark that some Northern Virginian officials saw as a joke he made about Fairfax County Board Chairman John F. Herrity's recent heart attack.

The mayor said in a letter Herrity received yesterday that he had been "shocked and distressed" to learn of the heart attack and "in no way" ever attempted to make light of it.

"If my remarks have offended you in any way, I offer my sincere apologies," Barry wrote. "I hope you are well . . . so that we can move forward with the pressing business of mutual interest to Fairfax and the District."

Fairfax officials had demanded that the mayor apologize for a comment he made at a news conference after Herrity's Jan. 10 attack.

Barry told reporters at that time that he had informed Herrity earlier that day that the District was not about to close its Lorton prison in Fairfax County and added: "Unfortunately, that news had some kind of effect on him."

Herrity was recuperating at his Springfield home yesterday. His spokesman, Bob Foreman, said Herrity "appreciates the mayor's concern" and is looking forward to working with him on several issues of mutual interest, including finding ways to make the prison in southern Fairfax safer.

Martha V. Pennino, vice chairman of the Board of Supervisors, who called Barry's original remark "a low blow from the gutter," said yesterday the apology was statesmanlike.

"I'm sure that the hatchet is buried and we can continue to work on mutual concerns," she said.