(Reuters) - A Michigan inmate who was killed last week after he grabbed an officer's gun in a courthouse and shot dead two bailiffs had earlier written a letter to his ex-wife vowing to escape or to die trying, the sheriff's department said on Friday.

Larry Gordon, 44, killed the two bailiffs and shot and injured two other people in the Berrien County courthouse in St. Joseph, Michigan, on July 11.

Gordon, who was in custody and faced multiple sex-crime charges and a potential life sentence, was handcuffed in the front as he was being moved from a courtroom to a holding cell in the courthouse.

On Friday, investigators distributed to news media an unsent letter found in Gordon's jail dorm after the attack. In the letter he apologized for causing his family harm, and wrote "I'm sorry" many times.

"I'm just trying to get free and I'll die trying," he wrote in the letter, dated the same day that he died. "They want to send me away for the rest of my life, I don't deserve that. That's not living. I'm not going to do it." He said he would be in hiding and living on the run.

Gordon faced multiple criminal charges related to allegations that he had held a teenage girl captive in a shed on the property where he lived with his former wife.

Prosecutors said he gave the girl drugs and coerced her to have sex with him. Methamphetamine was found in the shed.

The charges against Gordon included five counts of first-degree criminal sexual conduct, three counts of production of child sexually abusive material, two counts of assault by strangulation and others.

Investigators also released a time-line on Friday detailing three minutes of chaos in the courthouse after Gordon attacked a bailiff in a hallway outside a courtroom and began shooting. Gordon, who was handcuffed and holding the revolver he had grabbed from a deputy, briefly took a number of hostages and at gunpoint forced them to break out glass doors where he wanted to escape.

Gordon killed bailiffs Joseph Zangaro and Ron Kienzli, and wounded sheriff's deputy James Atterberry and a civilian women.

The sheriff's department has said it will review the procedure of handcuffing prisoners in front for court hearings.

(Reporting by Fiona Ortiz in Chicago; Editing by Leslie Adler)