An NYPD commander who was grilled by the FBI and saw boxes of records seized by Internal ­Affairs cops amid a widening corruption probe put a gun to his head and killed himself on Long Island Friday, sources said.

Inspector Michael Ameri, 44, head of the Highway District, “felt his career was in jeopardy” as the feds and the Internal Affairs Bureau eyed unauthorized escorts for members of the ­Orthodox Jewish community, the sources said.

“They went to his station house [Thursday] to get the escort logs. After that, someone called him,” a law-enforcement source said, referring to the unit’s facility off the Grand Central Parkway in Queens.

IAB cops took two years’ worth of police-escort files in the raid.

“He was very distraught about the visit. He felt his career was in jeopardy, and he couldn’t deal with the stress and not knowing when everything was going to come to a head,” another source said.

Ameri, the divorced father of a teenage boy, was found dead in his department-issued black Ford Taurus at 12:42 p.m. by Suffolk County homicide cops alongside Bergen Point Golf Course in West Babylon, about four miles from his house, sources said.

The day before his suicide, Ameri got a phone call from the head of his police union, Roy Richter, who tried to reassure him that he shouldn’t be so worried — that the IAB visit was focused mostly on a lieutenant who had just put in retirement papers. The lieutenant, one of Ameri’s closest friends, was cleared for retirement on Friday.

“I told him that he was not in any type of employment jeopardy,” Richter told The Post. “There was always that fear and concern and that worry. I thought I put those fears and concerns to rest. It’s obvious I didn’t.”

Investigators are examining whether cops provided police ­escorts for funerals and other events in exchange for cash and gifts — including from businessmen Jona Rechnitz and Jeremy Reichberg.

It was not clear whether damning evidence had been found on Ameri, a 23-year veteran, but he is one of several cops assigned to the unit who were grilled by the FBI about the alleged escorts.

A source said a spooked Ameri had recently distanced himself from Brooklyn’s Orthodox Jewish community. “Right before the Jewish holidays, Ameri told people close to him that he was very worried about the probe,” the source said, “and he cut ties with people who the feds were looking at, namely [Alex] ‘Shaya’ Lichtenstein.

“He actually told a high-ranking officer in the highway division to stay away from Shaya, cut off all communication.”

Lichtenstein, a Borough Park Shomrim patrol leader, was ­arrested by the feds on April 17 on charges that he paid off cops for gun permits.

Richter, head of the Captains Endowment Association, called Ameri an excellent cop.

“We are heartbroken at the loss of Michael Ameri and ask that you keep his family in your prayers during this traumatic time. Inspector Ameri is known as a dedicated police officer who excelled in all of his command ­assignments,” Richter said.

A statement released by the NYPD did not discuss Ameri’s career or the investigation, just details about the suicide. It referred questions to Suffolk cops.

“The Suffolk County Police Department will be conducting an investigation and we refer you to them for any further details about this incident,” the statement said.

Ameri was named commanding officer of the patrol unit, which investigates serious accidents, in May 2014.

Previously, he was commanding officer of the 78th Precinct in Park Slope, where he was friendly with Mayor de Blasio, who lived in the neighborhood.

Ameri was considered a key player in implementing de Blasio’s Vision Zero program to ­reduce traffic deaths.

“We are saddened to learn of the passing of Inspector Michael Ameri. Our thoughts and prayers are with his family during this difficult time,” de Blasio said.

No one was home at the cop’s residence in West Babylon Friday evening.

Investigators are looking at the escort allegations along with other potential corruption, including accusations that cops took cash for expediting gun permits and accepted lavish gifts from Rechnitz and Reichberg. Among the alleged gifts was a flight to Las Vegas — with a hooker on board.

At the same time Lichtenstein was allegedly bribing officers in Brooklyn’s gun-licensing division, two NYPD cops abruptly retired from the unit to start a business helping people get pistol permits.

Another cop was stripped of his gun and badge after he tried to retire last month, prompting his suspension because he was still a target of the feds’ probe.