A probationary cop who was axed for boozing with a police officer who allegedly ran over and killed a Brooklyn family is suing to get his job back.

John Welsh, 24, says in papers filed in Manhattan state Supreme Court that he was the victim of an “arbitrary, capricious and unlawful” firing caused solely by “substantial negative publicity” arising from Officer Joseph Gray’s deadly Aug. 4 accident.

Prosecutors charge that Gray, 40, had just finished a 12-hour drinking binge when he ran a red light and smashed into 8-months-pregnant Maria Herrera, her 4-year-old son, Andy, and her 16-year-old sister, Dilcia Peña.

Gray, who later quit the NYPD in disgrace, has been charged with four counts of manslaughter.

Welsh was a probationary officer in the 67th Precinct on Aug. 4 when he got a call at home at 8 a.m. inviting him to “a little get-together” for an engaged colleague at a parking lot next to Gray’s 72nd Precinct station house, the suit says.

Welsh says he got to the gated parking lot around 9 a.m., and “had a few beers” with several officers until around 11:30 a.m., when they went to the Wild West strip club “for something to eat.” Welsh again “had a few beers” before leaving for home at 12:45, the suit says, adding he was off-duty and “sober at all times.”

Gray, whom Welsh says he “did not know,” stayed at the club for several more hours before getting into the accident around 9 p.m.

Welsh and another probationary cop were fired days later, after police brass found out about the party in the parking lot.

The canned cop, whose father, grandfather and great-grandfather were all members of the NYPD, said he was told “informally” that he was fired for going to the strip club, which is off-limits to members of the 72nd Precinct – but not to members of Welsh’s 67th Precinct.

The suit maintains Welsh “has not violated any rule or regulation” of the NYPD, and is “not guilty of any on-the-job misconduct.”

A spokesman for the NYPD didn’t return a call for comment, but the threshold for firing probationary officers is much lower than for full police officers.