Two MTA workers were hit by a G train, one fatally, in Brooklyn early Thursday morning, police said.

Louis Gray, 53, and Jeffrey Fleming, 49, were on the tracks between the Fort Hamilton Parkway and Church Avenue stations just after midnight, a law enforcement source said. They were preparing the tracks for repairs when a southbound G train struck them, pinning them under the train, police and MTA officials said.

The two were rescued from the tracks through an emergency exit on street level near East Third Street and Canton Avenue, police and fire officials said.

Gray was pronounced dead at Maimonides Medical Center. Fleming was taken to New York Methodist Hospital in stable condition, police said. He suffered broken ribs, a source said.

Transit Workers Union Local 100 president John Samuelsen said the workers were performing routine maintenance.

“This tragedy highlights the extreme danger transit workers are in every time they step on the tracks,” he said.

The MTA said it is investigating the incident.

“The safety of all our workers is paramount and we are in the process of investigating this tragic incident,” New York City Transit president Ronnie Hakim said in a statement. “All safety standards are being reviewed with employees and a ‘safety stand down’ order — requiring all non-emergency track work to cease — has been issued while an investigation is underway.”

G train service resumed at 1:20 a.m., the MTA said.

With Vincent Barone and Alison Fox