BOSTON (AP) — A former assistant chief engineer for the firm that operates Massachusetts’ commuter rail service was charged, along with a second man, in a scheme to defraud the company of more than $8 million, federal prosecutors said Wednesday.

John Pigsley, 58, of Beverly, Massachusetts, was charged with wire fraud, conspiracy to commit wire fraud, tax evasion, filing a false tax return and structuring financial transactions to evade reporting requirements.

Pigsley, who worked as an assistant chief engineer of facilities for Keolis Commuter Services, appeared in court Wednesday. He pleaded not guilty to the charges and was released. His lawyer did not immediately return an email.

John Rafferty, 69, of Hale’s Location, New Hampshire, was also charged and agreed to plead guilty to one count of conspiracy to commit wire fraud, according to prosecutors.

Rafferty was not due in court Wednesday. A lawyer for Rafferty could not immediately be reached.

The money could have helped with repairs for the beleaguered Massachusetts Bay Transportation Authority, which oversees the greater Boston public transit system, investigators said. Keolis operates the commuter rail for the MBTA.

“Over the last few years, T ridership has had to endure its fair share of both acute and chronic issues. Today, unfortunately, we add fraud to that list,” U.S. Attorney Rachael Rollins said in a statement. “The $8 million they stole could have been used to ensure significantly safer, faster and more reliable transportation for riders. Instead, these men lined their pockets.”

Between July 2014 and November 2021, Pigsley and Rafferty allegedly defrauded Keolis of more than $4 million through a false invoicing scheme, according to the charging documents.

Rafferty bought vehicles, construction equipment, construction supplies and other items for Pigsley and a construction company partially owned by Pigsley, investigators said. Pigsley then directed Rafferty to recover the cost by submitting false and fraudulent invoices to Keolis from an electrical supply vendor where Rafferty worked as a general manager.

The fraudulent invoices included a percentage profit that Rafferty kept for himself, according to investigators.

Law enforcement also allege Rafferty spent more than $3 million on items for Pigsley and others — including at least nine trucks, seven Bobcat machines, $1 million in home building supplies and services, and a $54,000 camper — for which Keolis paid Rafferty more than $4 million based on false invoices.

Pigsley also directed Keolis to purchase copper wire, which he then stole and sold to scrap metal businesses, keeping the cash proceeds for himself, according to investigators.

Pigsley personally collected the copper wire from vendors or had it delivered to his home, prosecutors said. He then allegedly transported the wire to scrap yards, where he traded it for thousands of dollars in cash several times a month — sometimes more than once a day. All told, he collected more than $4.5 million in cash by stealing and scrapping copper wire, according to the charging document.

Investigators also allege Pigsley defrauded the IRS by failing to pay federal income taxes on funds he received from the invoicing scheme and from selling copper wire.

Pigsley faces up to 20 years in prison for the charges of wire fraud and wire fraud conspiracy, as well as additional prison time and fines for the other charges.

Rafferty faces up to five years in prison on the charge of conspiracy to commit wire fraud.