John Ray, a 35-year-old lawyer who was backed by Mayor Marion Barry, was chosen on the sixth ballot last night by a sharply divided D.C. Democratic State Committee to be Barry's interim replacement on the City Council.

In a suspenseful three-hour contest Ray, a one-time mayoral candidate, edged out legislative aide Johnny Barnes and realtor H. R. Crawford to win the right to Barry's old atlarge seat until after a May 1 special election.

The choice of Ray was an intraparty political victory for Barry, who took an active part in last night's deliberations, buttonholing state committee members in the hallway of the District Building between rounds of voting.

Despite the outcome the committee, which was bitterly split during last fall's close three-way battle for the party's mayoral nomination, appeared to remain significantly at odds with the new mayor and titular party chief.

Opposition to Ray was spearheaded by Sharon Pratt Dixon, the District's national committeewoman and the wife of new City Council Chairman Arrington Dixon. Sharon Dixon supported Sterling Tucker in the mayoral primary.

Committee Chairman Robert B. Washington Jr., who also had supported Tucker, backed Barnes last night.

Five open ballots followed an initial secret ballot. Washington, whom some advisers to Barry say privately they would like replaced, voted for Barnes on the first four public ballots, and passed on the last.

Under committee rules at least 27 votes -- a majority of the committee's total membership of 52 -- are required for victory.

The deciding vote was cast shortly before 11 p.m. by Absalom Jordan Sr., a committee member from Ward 1. Until then he had supported former council member Douglas E. Moore.

Jordan's vote made the count on the sixth ballot 27 for Ray, 13 for Barnes and one for Jerry Cooper, chairman of the Ward 1 Democrats. Eight committee members had passed on the final ballot before Jordan's vote.

On the previous round, Ray had received 26 votes to 21 for Barnes.

Crawford, who had never received more than 19 votes, withdrew after four rounds, saying he was acting "in the interest of party unity."

From early on, Ray was consistently the top vote-getter, receiving 20 votes in the first round.

Vote totals but not the names of those who had backed each candidate were announced for the first round.

In campaigning for the post Ray had contended that his experience as a lawyer in all three branches of government made him best qualified. Barry, who did not campaign actively for Ray until this weekend, used the same argument.

Ray's opponents contended he would be "the mayor's man" on the council. Ray had dropped out of the mayoral race in August and actively backed Barry.

In addition, the oppoents said Barry was trying to be a "political boss" by endorsing a candidate, and they also argued that Ray had come to city politics too recently to be chosen for the coveted post.

Much of last night's voting appeared a "stop-Ray" effort. From a 19-vote high on the second ballot, Crawford fell to 18 and then to 11. Barnes, who got no more than six votes in any of the first three rounds, gained support as Crawford lost it.

Before the meeting supporters of Barnes, 31, a legislative assistant to Del. Walter E. Fauntroy, (D-D.C.) had hoped Barnes could win as a compromise candidate on a late ballot.

But Ray's support remained firm and Crawford's backing failed to deadlock the voting.

Ray is expected to take office within a week, as soon as his election is certified by the D.C. Board of Elections and Ethics.

The interim post is considered a useful stepping stone to victory in the special election.

Eight other persons sought the appointment in addition to Ray, Barnes and Crawford. All failed to get significant support.