The president of the LIRR was fired on Wednesday to be replaced by someone with a stronger mechanical background in running trains, sources told the Post.

Helena Williams, the railroad’s first female president, had headed it for almost seven years.

MTA Chairman Thomas Prendergast decided to replace her with Patrick Nowakowski, the executive director of a project to build a rail line between Washington, D.C. and Dulles, Virgnia.

He has also worked for over 27 years at the Southeastern Pennsylvania Transportation Authority, and has a background in civil engineering.

After the Metro-North derailment and safety fiascos, Prendergast wants people in top positions at MTA to have strong operations backgrounds, sources said.

“I was very surprised,” Williams told the Post. “I had a great run. I am very proud of what I accomplished at the railroad.”

Williams has a solid record at the LIRR, but didn’t rise up the ranks through railroad operations, sources said.

She is a lawyer with a background in labor issues, and has worked in government on Long Island.

She is the railroad’s longest-serving president in decades, and also the first woman to run any MTA agency.

She has been with the authority for two decades.

Joseph Giulietti, who replaced former Metro-North’s president Howard Permut, worked much of his career in operations, and has driven trains before.