An off-duty city cop who was so drunk that he fired his service revolver into a car stopped at a red light, nearly killing two men, has just cost the city $8.2 million.

In a deal signed late Friday, the NYPD agreed to fork over $6.9 million to Joseph Felice, who was shot six times by Officer Brendan Cronin in 2014.

Felice’s pal Robert Borrelli, who was also in the car but not injured, will get $1.3 million.

Felice and Borrelli have accused the NYPD of paving the way for Cronin’s shooting rampage by ­allowing him to drink on the job during intensive gun training at the NYPD’s Rodman’s Neck training facility in The Bronx.

“Information we obtained shows the NYPD’s own training facility had a culture of drinking,” said Debra Cohen, a lawyer for the two men.

“They need to recognize they have a problem,” said Randolph McLaughlin, another lawyer for the men. “This is not the only incident of bad cops doing drunk things,” he said.

“Settling this case was in the best interests of the city,” said a spokesman for the city’s Law Department.

The two New Rochelle men were driving home from a hockey game in Mount Vernon in April 2014 when Cronin, now 30, shot at them following a day of gun training and heavy drinking.

Cronin spent the day at the Rodman’s Neck training facility learning about “dynamic vehicle takedowns,” which included shooting at cars, the lawsuit said. For lunch, he went with his supervisor and fellow officers to a nearby pub, the lawsuit said.

After the training ended, Cronin went back to the same City Island eatery — with two detectives who led the training — to drink for as many as five hours, the suit said.

Cronin “consumed at least 10 drinks consisting of Jameson Whiskey shots and beer” while there, according to the complaint.

Despite the heavy drinking, Cronin was allowed to drive home carrying his weapon, the lawsuit said.

On the way, he stopped on the side of the road at Lincoln Avenue in Pelham, aimed his pistol at a car stopped at a red light and fired shots from right to left — as if he were back in training.

Cronin, 30, pleaded guilty in 2015 to four felony counts and one misdemeanor DWI count. He was sentenced in 2016 to nine years in state prison and booted from the NYPD. He had joined the force in 2007 and worked in the 46th Precinct in The Bronx.