A group of D.C. administrative law judges voted to unionize Thursday, bringing to a close a two-year effort to organize that has pitted the judges against agency managers and, at times, the administration of Mayor Vincent C. Gray.

Some judges of the Office of Administrative Hearings, who hear and rule on cases involving numerous city agencies, have sought to organize a union since 2012, when they were in the middle of a high-pitched conflict with the agency’s chief.

Thursday’s 19-to-5 vote, reported by the International Federation of Professional and Technical Engineers, which sponsored the organizing effort, puts the agency’s judges in the company of many other judges and hearing examiners across the country who have formed unions. The engineers union, for instance, represents nearly 2,000 federal administrative law judges.

“It certainly has taken far longer than it should have,” said Paul Shearon, the union’s secretary-treasurer, referring to Gray administration labor officials’ refusal to recognize the union without a vote and later efforts by the agency’s former chief judge, Mary Oates Walker, to oppose the organizing.

Pending the certification of the election by a city labor-relations board, the agency’s 28 rank-and-file judges will be able to collectively bargain with management and establish a contract setting out workplace provisions and grievances.

“They’ll be able to fend off the kind of corruption that has happened in the leadership in the past,” Shearon said.

The vote comes a week after Walker settled an ethics complaint against her by admitting to creating the appearance of a conflict of interest and “preferential treatment” of a subordinate. She agreed to pay a $20,000 fine to settle the matter, which initially involved 19 ethics charges.

Walker had been subject to blistering criticism from some of her subordinate judges, who accused her in a June 2012 letter of being “unprofessional, erratic, and at times demeaning.” The organizing effort began shortly afterward and was opposed by Walker, who argued that the judges were managers who did not have the right to form a union.

After the Gray administration withdrew from the matter last year, Walker hired outside law firms to fight the organizing effort. Doxie McCoy, a spokeswoman for Gray (D), said the mayor supports the judges’ right to unionize.

Gray fired Walker after the ethics charges were filed against her this year. An attorney for Walker, who has characterized herself as a reformer who was undermined by disgruntled veteran judges, said last week that she would continue to fight her dismissal.

Her interim replacement as chief judge is Wanda R. Tucker, who was among the judges who signed the 2012 letter and supported the subsequent organization effort. Tucker’s permanent appointment is before the D.C. Council.

“It’s made a big difference already in the working environment for the judges,” Shearon said of Tucker’s ascension. “That doesn’t mean sometime in the future that union and management aren’t going to have a number of issues they are going to disagree on . . . but it’s good to have someone in management who is good and is willing to work with them.”