L.I.R.R. officials said they received figures from the Association of American Railroads, a trade group, showing that New York & Atlantic’s safety record was better than average from 2011 to 2013, the three years before the railway sent a renewal notice. But the railway came under scrutiny in 2015 after a train went through three crossings before the gates that block vehicles had been lowered, then plowed into a tractor-trailer in Queens, sparking a fire and causing minor injuries.

Federal investigators later issued a report concluding that New York & Atlantic had allowed engineers to operate locomotives without proper documentation that they were qualified under federal regulations. During the inquiry, the railway failed to produce requested records that regulations say should be “readily provided,” according to the report by the Federal Railroad Administration.

By the time the report was issued, New York & Atlantic’s contract had been renewed. In 2016, Thomas F. Prendergast, then the chairman of the Metropolitan Transportation Authority, which oversees the L.I.R.R., said the contract could be reconsidered in light of the federal findings, according to Newsday, but it has remained in effect. Still, L.I.R.R. officials said they have insisted that New York & Atlantic implement a review of its safety practices and compliance with regulations.

A spokesman for the L.I.R.R. declined to comment on the lawsuit.

The workers’ lawsuit claims New York & Atlantic had a two-tiered system of full-time employees: nonimmigrants and others whom the lawsuit described as being “of indigenous or Afro Dominican ethnicity” and “perceived immigrants.”

The second group, the lawsuit said, was hired from Home Depot parking lots and told to enter the rail yard by scaling a fence instead of through a gate. Those workers, the suit added, were given a segregated and substandard changing area, subjected to racial slurs and denied protective equipment and training while working for unlawfully low pay in dangerous conditions.

Workers said that they installed and repaired rails, used chain saws to remove trees felled by storms and sprayed herbicides and pesticides. Several workers said they were not instructed how to properly use tools. Some said they watched YouTube videos to learn how to perform certain tasks.