Alexandria lawyer Alfred D. Swersky won the endorsement of the Alexandria Bar Association yesterday for the city's vacant Circuit Court judgeship, outpolling his well-known rival, Alexandria Commonwealth's Attorney John E. Kloch.

Swersky, 43, a former federal prosecutor, outpolled Kloch, garnering 191 votes to Kloch's 162.

"I'm elated," said Swersky as his colleagues congratulated him, a few prematurely calling him "Your Honor."

The 400-member bar association, which had a record turnout at its meeting yesterday, will now forward Swersky's name to Gov. Charles S. Robb, who appoints Virginia judges when the General Assembly is not in session. The governor is not bound by the bar's recommendation, but generally follows it.

The Alexandria judgeship, which pays $63,700 a year, became vacant when Albert H. Grenadier died of cancer March 29.

"I've wanted to be a judge for a long time," said Swersky, who also threw his name in for contention last year when the bar association endorsed Circuit Court Judge Donald M. Haddock.

Kloch, a Democrat who was considered by many to be the leading contender for the endorsement, said later he would seek a third term as commonwealth's attorney in the November elections. Several bar members yesterday said that Swersky's edge over Kloch was a result of his wider experience in civil law, his high regard among city attorneys and the reluctance of the city's lawyers to see a prosecutor on the bench.

Attorney Philip Hirschkop also said that a Supreme Court opinion that stated that Kloch in 1981 had introduced misleading evidence into a trial also "bothered some of us." Kloch denied any impropriety.

Swersky has practiced in his own firm since 1971.