The Oklahoma doctor involved in the bungled execution of Clayton D. Lockett in April made one last frantic attempt to insert an intravenous line in the prisoner’s groin but struck an artery by accident and was sprayed with blood, according to a document filed in Federal District Court.

“It was a bloody mess,” the document quotes Anita Trammell, the warden of the Oklahoma state prison where the execution took place, as saying in an interview with state investigators.

The court document, filed late Friday, includes gruesome details about Mr. Lockett’s final moments after he seemed to regain consciousness on the execution table, writhing in pain. The brief, filed in a lawsuit seeking to stop the executions of four prisoners in early 2015, also provides new evidence of the poor training and disarray among state officials, the paramedic who failed in numerous attempts to place a catheter and the doctor who tried to complete the task.

The prolonged and apparently agonizing death of Mr. Lockett, who was convicted of shooting a 19-year-old woman in 1999 and burying her alive, prompted new debate about the reliability of lethal injection and over questions about the drug combinations that states have tried as alternatives when the traditionally used barbiturates became scarce.