Prosecution against engineer Brandon Bostian, who derailed an Amtrak train two years ago in Philadelphia, ended in stunning fashion Tuesday when a judge ruled there was not enough evidence to warrant a criminal trial.

Philadelphia Municipal Court Judge Thomas Gehret dismissed all counts against Bostian after a four-hour hearing that centered on what responsibility the engineer should bear for eight deaths and more than 100 injuries caused by the May 12, 2015, accident.

"Based on that evidence," Gehret said, "I think it's more likely than not this was an accident and not criminal."

Bostian had been charged with eight counts of involuntary manslaughter, one count of causing or risking a catastrophe, and 238 counts of reckless endangerment.

He remained stoic through the hearing even after learning he would not face trial and did not comment afterward. His lawyer, Brian J. McMonagle, argued — fiercely at times — that Bostian had committed a mistake, not a crime.

"It's a horrible tragedy, but the law recognizes there's a big difference between an accident and a crime," McMonagle said during the hearing.

The Pennsylvania Attorney General's Office declined to say whether it would seek other ways to charge Bostian. State prosecutors brought a manslaughter case against Bostian after the Philadelphia District Attorney's Office declined to press charges just days before a statute of limitations expired on the reckless endangerment charge.

"We are carefully reviewing the judge's decision, notes of testimony, and our prosecutorial responsibilities in this case going forward," said Joe Grace, spokesman for the Attorney General's Office.

Attending the hearing was attorney Thomas R. Kline, who pushed for criminal charges against the engineer on behalf of a client whose daughter, Rachel Jacobs, died in the derailment. The family sought a judge's order that Bostian be charged, which led the attorney general to act.

Bostian drove the seven-car train that derailed at the Frankford Curve in Port Richmond. The train had accelerated to 106 mph — more than twice the speed posted — as it approached the curve, according to findings by the National Transportation Safety Board.

The federal investigation concluded that Bostian had no alcohol or drugs in his system and was not using his cellphone at the time of the derailment. Bostian told the NTSB that he did not remember what had happened. The federal agency's review concluded that he lost "situational awareness," probably because of radio chatter about a rock hitting a SEPTA train near the curve shortly before the derailment.

Bostian has been on unpaid administrative leave from his Amtrak position since the crash.

Tuesday's hearing began with what appeared to be bad news for Bostian. The judge denied McMonagle's motion to dismiss charges, saying the Attorney General's Office had acted properly in the steps it took to charge Bostian.

What followed resembled an abbreviated trial, in which prosecutor and defense offered arguments on whether there was enough evidence of criminality to warrant a trial.

Deputy Attorney General Christopher Phillips argued that on the day of the crash, Bostian had one responsibility: to maintain a speed that was safe for his 250 passengers. He instead accelerated the train three times as he approached a curve Phillips described as one of the most dangerous on the Northeast Corridor.

"He acted with gross negligence," Phillips said, explaining to Gehret why Bostian's behavior was criminal. "He ignored the risks that were involved."

The prosecutor listed graphic details of the injuries suffered by the people who died. Among his witnesses was Blair Berman, who encountered Bostian just after the derailment.

Berman, tossed from the train and hobbled by her injuries, asked to use his phone. Initially, he refused, but Berman didn't take no for an answer. "I was very aggressive," she recalled.

As she called her father, she asked Bostian where they were, and he was specific about the location and the train number, 188. That level of awareness seemed at odds with other recollections. Philadelphia police Detective Joseph Knoll recalled meeting Bostian at Einstein Medical Center and hearing him ask about his whereabouts.

"Are we in New York?" Knoll recalled Bostian saying. "I heard him say that."

McMonagle asked both Berman and Knoll whether they were aware Bostian had sustained a head injury in the crash, and both said they had seen evidence of an injury. Bostian suffered a concussion in the crash.

John Hines, a senior director of compliance and certification with Amtrak and a contributor to the rail company's crash investigation, described Bostian's training, including eight weeks of classroom and simulator work, as well as on-the-job training that required him to memorize his route and be familiar with its speed restrictions. The engineer properly obeyed speed regulations through Philadelphia's tracks until nearing the Frankford Curve, where he accelerated steadily from 80 mph to 106 mph.

Amtrak Police Detective Joseph Degrazia testified that Bostian had safely operated trains through the area where the derailment occurred 25 times in the six weeks before the derailment.

McMonagle, though, pounced on a key detail the prosecution did not raise, that about the time of the derailment, in the same area, a SEPTA train reported being struck by a rock. Bostian had been listening to radio chatter about that incident, Hines said, and passed the damaged SEPTA train in the minutes before the derailment. McMonagle didn't dispute that Bostian was going dangerously fast as he entered the turn. Instead, he raised an explanation for the disaster that came up a year and a half ago when the NTSB concluded its investigation, that Bostian had become confused as to where he was.

"Speed alone," he said, "is not enough."