Torrey Twane McNabb. (Alabama Department of Corrections via AP)

Then, in a final act of defiance, he cursed at the state of Alabama.

“I hate you motherf—ers. I hate you. I hate you,” he said, according to al.com, whose reporter witnessed the execution Thursday night.

Just before he lost consciousness, McNabb raised both of his middle fingers.

The execution was carried out just before 9 p.m. Central at Holman Correctional Facility in Atmore, Ala.

McNabb, 40, was pronounced dead less than an hour later.

He had been condemned to die after he was convicted of the death of Montgomery police officer Anderson Gordon. The 30-year-old officer was killed on Sept. 24, 1997, after he arrived at a crash that McNabb caused while fleeing a bail bondsman, prosecutors said.

McNabb shot the officer five times while Gordon was sitting in his patrol car.

“Over 20 years ago, we lost a companion, a father, a brother and a friend who only wanted to make a difference in his community,” the officer’s family said in a statement that was read by Alabama Department of Corrections Commissioner Jefferson Dunn at a news conference. “. . . Although the wounds of having a family member murdered can never be healed, through this tragedy, the Gordon family has remained strong and will continue to be resilient. . . . Though this has been a difficult day for the Gordon family, we also continue to pray for the family of Torrey McNabb.”

McNabb’s lawyers sought to stop the execution because of his involvement in a pending lawsuit challenging the state’s lethal injection procedure.

Inmates, including McNabb, argued that the procedure involves a controversial sedative that does not make people completely unconscious, making them suffer an agonizing death as subsequent drugs are injected to stop their heart and lungs.

Officer Anderson Gordon. (Montgomery Police Department via AP)

A three-judge panel of the U.S. Court of Appeals for the 11th Circuit, which has jurisdiction in Alabama, had earlier upheld a stay on the execution to allow for more proceedings on the lawsuit, the Associated Press reported. The decision prompted the Alabama Attorney General’s Office to ask the Supreme Court to intervene, arguing that the justices had already allowed four other lethal injections involving the sedative midazolam.

The Supreme Court delayed McNabb’s execution just minutes before the procedure was supposed to start to consider his attorneys’ request. The justices allowed the execution to proceed two hours later.

During the execution, McNabb’s family and attorneys expressed concerns that he remained conscious after the sedative was injected.

“He’s going to wake up,” one of his family members whispered, according to the AP.

McNabb appeared to be breathing for 20 minutes after he was injected with the midazolam. He moved his head, grimaced and raised his arms after a guard pinched him, said his name and pulled back his eyelid to check if he was conscious, the AP reported.

Dunn, the commissioner, said the movements were involuntary.

In 2015, the Supreme Court heard a case involving Oklahoma’s use of midazolam after those high-profile executions. A bitterly divided court upheld the use of the drug.

In December, a deadlocked Supreme Court decided not to intervene in the execution of an Alabama inmate, who coughed and heaved for 13 minutes before he died.

Mark Berman and Robert Barnes contributed to this report.