President Judge Marsha Neifield of Philadelphia Municipal Court ordered the city District Attorney's Office on Thursday to reverse course and charge Amtrak engineer Brandon Bostian with involuntary manslaughter and reckless endangerment.

To avoid a potential conflict of interest, the District Attorney's Office responded that it would refer the prosecution to the state attorney general.

Neifield issued the order following a request from lawyers for victims of the May 12, 2015, derailment of Amtrak Train 188 that the case be reopened. On Tuesday, the District Attorney's Office had said that, following a lengthy investigation, it had concluded there was insufficient evidence to bring charges.

The following day, lawyers with the office of Richard A. Sprague, a prominent city lawyer and former first assistant district attorney, formally asked the District Attorney's Office to accept a criminal complaint filed by the husband and father of Rachel Jacobs, a young mother killed in the crash.

But the District Attorney's Office declined, setting the stage for Thursday's hearing before Neifield.

Plaintiffs lawyers Thomas R. Kline and Robert Mongeluzzi, who between them represented 32 victims in lawsuits against Amtrak, joined in the request for criminal charges against Bostian.

The lawyers asked that Bostian be charged with involuntary manslaughter and reckless endangerment. The statute of limitations for charges of reckless endangerment expires on Friday.

The decision not to prosecute "was a shock," Sprague said at a Thursday evening news conference. "Can you imagine someone driving down Market Street at 100 miles per hour, hitting people, killing people, and the DA saying we don't have a basis for prosecuting anybody?"

In a statement Thursday afternoon, Cameron L. Kline, communications director for the District Attorney's Office, said, "President Judge Neifield has ordered the filing of two private criminal complaints as a result of the Amtrak Train 188 derailment. In view of our earlier decision not to file charges, we have referred this prosecution to the Pennsylvania attorney general. We take this action to avoid the potential for any apparent conflict of interest, consistent with the Pennsylvania Commonwealth Attorney's Act."

Although it is unusual for a judge to order a prosecutor to file criminal charges, there is a basis in Pennsylvania law for the judiciary to step in and essentially take control of a criminal investigation, said Temple University law professor Jules Epstein.

The hurdles for such action typically are high, he said, because of the separation-of-powers doctrine, which grants each branch of government wide discretion within its own sphere of authority.

But Epstein said case law in Pennsylvania lays down guidelines for when a judge can compel a prosecutor to accept a citizen's criminal complaint, the scenario that played out before Neifield on Thursday. Courts are more inclined to hear such requests when there is a dispute over the legal basis for bringing charges, Epstein said. The standard is more stringent when a prosecutor, as a matter of policy, declines to bring criminal charges.

For example, prosecutors may choose as a matter of policy to devote fewer resources to economic crimes, preferring instead to focus on public safety and prosecute violent criminal behavior.

"The law gives prosecutors tremendous discretion on whether to bring charges," Epstein said.

The early-evening Amtrak derailment on a northbound stretch of track in the Port Richmond section of the city killed eight and left hundreds more injured.

The train was traveling 106 mph, more than twice the posted speed limit, when it entered a sharp curve at Frankford Junction and derailed. Bostian has said he has no recollection of the moments leading up the accident, nor any knowledge of how it happened.

The National Transportation Safety Board concluded that, in the moments before the accident, Bostian was distracted by reports of a rock being thrown at a nearby SEPTA train. He had no drugs or alcohol in his system and had not been on his cellphone.

The District Attorney's Office said Tuesday that it had concluded a nearly two-year-long investigation of the crash without bringing charges against Bostian.

Amtrak has taken responsibility for the crash and has since installed an automatic braking system on its Northeast Corridor rails that would have  prevented the derailment.