Updated

A Missouri execution has been delayed until at least midday Wednesday after a federal judge granted a last-minute stay.

John Middleton was scheduled to die one minute after midnight Wednesday for killing three people in rural northern Missouri in 1995. Less than two hours before the execution, U.S. District Judge Catherine Perry granted a stay, ruling that there was enough evidence of mental illness that a hearing should be held.

Courts have established that executing the mentally ill is unconstitutional.

Missouri Attorney General Chris Koster appealed to the 8th U.S. Circuit Court of Appeals, but that court adjourned for the night without a ruling.

The state could execute Middleton at any time Wednesday if the stay is lifted.

It was a confusing end to a day that saw a flurry of court actions. Perry first granted a stay early Tuesday, but it was overturned by the appeals court. The U.S. Supreme Court refused to overturn the appeals court ruling, and also declined to halt the execution on several other grounds, including the contention by Middleton's attorneys that he was innocent of the crimes.

Middleton's attorneys then went back to Perry, who once again granted a stay. However the appeals court eventually rules, the case is likely to end up again in the U.S. Supreme Court.

The death warrant expires at midnight Thursday, so if Middleton is not executed by then, the Missouri Supreme Court would have to set a new date. State witnesses and media were told to report back to the prison by 10:30 a.m.

Middleton, 54, would be the sixth man put to death in Missouri this year -- only Florida and Texas have performed more executions in 2014 with seven each.

He was convicted of killing Randy "Happy" Hamilton, Stacey Hodge and Alfred Pinegar out of concern that they would tell police about Middleton's methamphetamine dealing. Middleton's girlfriend, Maggie Hodges, is serving life in prison after pleading guilty to second-degree murder in all three cases.

Middleton's attorneys contend that the wrong man was arrested, citing new evidence that included a witness who came forward in February.

"We're looking at a situation where if (Middleton) had zealous representation at trial he likely would have been acquitted," attorney Joseph Perkovich said.

Koster disagreed. "The time for enforcement of Missouri's criminal judgment against John Middleton is long overdue," Koster wrote in a court response on Tuesday.

Middleton was a meth dealer in sparsely-populated northern Missouri in the mid-1990s. After several drug suspects were arrested on June 10, 1995, he allegedly told a friend, "The snitches around here are going to start going down."

A day later, according to court records, Middleton and his girlfriend met Hamilton and Hodge on a gravel road. Prosecutors said Middleton shot and killed them both and put the bodies in the trunk of Hamilton's car.

Pinegar, another meth dealer, was shot in the face on June 23, 1995. His body was found in a field near Bethany.

Middleton allegedly told acquaintances about his exploits. He was charged in all three killings and convicted in 1997.

A witness with another story emerged this year.

In February, a man whose name is not disclosed because he fears retribution signed an affidavit saying that two rival meth dealers drove him to a rural area soon after Pinegar's death and accused him of being a snitch. He said the men showed him Pinegar's body, saying, "There's already been three people killed. You want to be number four?"

The new witness said the two dealers then beat him unconscious with a baseball bat and raped his girlfriend.

Harrison County Sheriff Josh Eckerson agreed to take a new look at the case, but said his investigation found no evidence to back up the new assertions. He is convinced that Middleton was the real killer.