Jim Forsyth, Reuters

The JetBlue Airways pilot whose behavior on a flight forced the plane to make an emergency landing in Texas was ordered conditionally released by a federal judge in Amarillo, Texas, on Friday.

U.S. District Judge Mary Lou Robinson ruled Clayton Osbon, 49, "would not create a substantial risk of bodily injury to another person or serious damage to the property of another" if released.

Osbon pleaded not guilty by reason of insanity in July to a criminal charge of interference with a flight crew and was ordered examined by psychiatrists for the U.S. Bureau of Prisons. A judge ruled him not guilty by reason of insanity and Osbon was sent to the Federal Medical Center in Butner, North Carolina.

On a March 27 flight from New York City to Las Vegas, Osbon began running through the aisles of the plane screaming about Iraq, Iran and al Qaeda, yelling, "We're not going to Vegas" and "You'd better start praying now!" An FBI report says the first officer on the flight managed to lock Osbon out of the cabin while passengers subdued him and another pilot made the decision to land in Amarillo.

A psychiatrist later attributed the incident to a brief psychiatric disorder brought on by lack of sleep, according to court documents.

Robinson set out a number of conditions for Osbon's release, including a stipulation that he not board a plane without court permission. He also is prohibited from communicating with anyone who was on board the JetBlue flight. He is forbidden from purchasing alcohol, using any controlled substances and must follow the psychological care recommended by his physicians.

Osbon will be released after his lawyers and federal prosecutors agree on a date. Robinson said in her written order that neither federal prosecutors nor the government objected to his release.

Osbon could have received up to 20 years in prison or been committed to a mental health facility.

Several passengers on board the flight have sued the airline, claiming JetBlue should have known that Osbon was not fit to fly that day.