When he hailed a cab outside an Uptown bar in January 2012, Cook County correctional officer Timothy Masterson was drunk, bleeding and looked like he’d been beaten up, according to sheriff’s records.

Masterson, a $66,000-a-year jail guard, was a handful for his cabby, who flagged down two Chicago cops for help, the records show.

The jail guard responded by pulling his gun and telling the cabby: “Drive, or I’ll blow your head off,” according to a complaint brought against him by Cook County Sheriff Tom Dart’s office that led to his firing.

Timothy Masterson in 2012 Chicago Police Department mug shot.

Timothy Masterson in 2012 Chicago Police Department mug shot.

Masterson — who says he’s “been sober now for over three years” and that “the punishment doesn’t fit the crime” — was arrested and ended up pleading guilty to aggravated assault.

But now his firing and those of at least two-dozen others — including jail guards, courtroom deputies and sheriff’s police — could come into question as the result of a court ruling last year.

In August, ruling in a separate case on a lawsuit filed by former sheriff’s police officer Percy Taylor, Cook County Judge Neil Cohen reversed Taylor’s 2012 firing and ruled Taylor was owed lost wages from his $79,000-a-year job. That order is on hold pending an appeal.

Taylor had been fired after being accused of shooting a neighbor’s truck with an air rifle and failing to report an arrest in Missouri on a drunk-driving charge he was later convicted of.

But Cohen ruled the Cook County Sheriff’s Merit Board — a tribunal appointed by the sheriff that handles firings — wasn’t “lawfully constituted” when it voted to dismiss Taylor.

In fact, the judge found, the board hadn’t been since 2011 — which, if his ruling is upheld on appeal, could also call the firings of other employees into question, legal experts say.

The law, which Cohen called “unambiguous,” says the Merit Board’s seven commissioners — each paid a $26,000 yearly salary — must be appointed to six-year terms. If not, their decisions are “void and may be attacked at any time,” according to the judge.

Records show that, since 2008, six sheriff’s Merit Board commissioners have not been appointed to six-year terms. One commissioner was given a term of just nine months.

That could give employees fired since then a chance to return to work and receive back pay, though Dart could move to fire them again, experts say.

A top Dart aide, though, says the sheriff’s office expects the Illinois Appellate Court to overturn Cohen’s ruling.

“We feel very confident [the board] is lawful,” says Cara Smith, who oversees the jail.

Still, at Dart’s request, the Cook County Board reappointed five Merit Board commissioners, retroactively giving them six-year terms.

Rick Linden, Taylor’s attorney, calls that move “outrageous.”

“It’s arrogance and sloppiness combined,” says Linden. “It’s disingenuous for them — four years later — to make their appointments retroactive to try to undo what they didn’t do properly in the first place.”

An attorney not involved in the case, Keri-Lyn Krafthefer, a municipal law expert with the firm Ancel-Glink, says Cohen’s ruling was “totally consistent” with past court decisions and that the Merit Board’s firing of Taylor “can’t stand.”

Scott F. Uhler, another attorney specializing in municipal law, agrees. “A board that has issued [decisions] without jurisdiction most likely has acted to make decisions that are void,” Uhler says.

The length of the Merit Board members’ terms might seem a minor technicality. But there’s a good reason to have commissioners assured of a term longer than the four-year term to which the sheriff is elected, says Nadav Shoked, an associate professor at Northwestern University School of Law.

“You want to create a board that is independent,” says Shoked, or commissioners might be left to worry that, “if I don’t give him what [Dart] wants, he can choose to not appoint me next year.”

Masterson, the jail guard fired after the incident in Uptown in 2012, says he has hired a lawyer and is trying to get his job back.

“I own up and take responsibility for my actions, but I was also a valuable employee who had multiple commendations,” he says.

Among other sheriff’s employees whose firings could be affected by the outcome of the sheriff’s appeal in the Taylor case is correctional officer Stephon Lloyd, fired in 2012 after Glenwood police charged him in October 2011 with assaulting a female family member.

Lloyd, who could not be reached for comment, initially was charged with multiple counts of aggravated battery and attempted sexual assault. Under a deal with prosecutors, Lloyd pleaded guilty to aggravated domestic battery in 2012 and was sentenced to two years of probation, which he completed in September.