October 6, 1970. While on vacation in Istanbul, Turkey, American college student Billy Hayes (Brad Davis) straps several pounds of hashish (about two kilograms) to his body. The film's soundtrack consists of an increasing heartbeat as Billy, nervous at being caught smuggling, makes his way with his girlfriend, Susan (Irene Miracle), through customs. Billy perspires heavily, noticed by the middle aged customs agent who checks his bag. After their bags are searched, both Billy and Susan board a shuttle bus to their plane. Billy smiles, thinking he is out of danger. However, he notices that a large detachment of armed police and soldiers have taken up positions just outside the plane. Unable to detach and discard the hashish, and sweating heavily, Billy is arrested on the spot when he is frisked by a young Turkish policeman. Billy is taken away and back to the terminal and searched, forced to stand around in his underwear. After he is allowed to dress, the Turkish security chief of the airport makes his stand for several press photographs of him holding the confiscated drugs with the smiling customs officers.
A little later, Billy meets a man, Tex (Bo Hopkins), from the US Department of State. He tells Billy that the recent terrorist airline hijackings have made the Turks much more fanatical about airport security and that the potency or type of drug that Billy was caught with doesn't matter: the Turkish government wants to appear tough on smuggling. Tex takes Billy to a local police station and is interrogated where Tex translates for a local Turkish detective whom offers Billy freedom if he points out who sold him the hash.
The next day, when Billy takes Tex out into an Istanbul bazaar to find the man he bought the hash from, Billy tries to run from his security escort. He is quickly caught by Tex himself, whose previously friendly attitude suddenly changes for the worse.
During his first night in holding, Billy sneaks out of his tiny cell and takes a blanket. He is later rousted out of his cell by a large guard named Hamidou (Paul L. Smith), the chief of guards, who takes him to another filthy room, trusses Billy's ankles in the air and hits the soles of his feet repeatedly with his club for stealing the blanket as well as hitting a trustee. Billy's feet swell immensely and he is left in horrific pain. However the next morning, a small group of prisoners, Jimmy (Randy Quaid), an American, Max (John Hurt), an Englishman and Erich, a Swede, get him on his feet and walking (they tell him his feet will continue to swell and his recovery will be longer if he doesn't move around). Jimmy was sentenced for robbing a mosque and Erich was busted for smuggling about 100 grams of hash and given a 12-year sentence. Max has been in prison the longest for drug dealing (seven years and counting) while Erich has already served four years and Jimmy around three. Jimmy tells Billy that the prison is a dangerous place for foreigners like themselves and that no one can be trusted, not even the young children, who are often criminal- and sex slaves for the other imprisoned men.
Several weeks later, Billy appears before a local Turkish court before a panel of three judges to hear his case. Billy's father (Mike Kelvin) arrives where he hires him a Turkish lawyer to defend him. But Billy's uninterested lawyer does little to combat the charges brought by an angry prosecutor, who wants Billy charged with more than possession: if Billy is charged with smuggling over mere possession, his sentence will be heavier. After the three judges deliberate for an uncertain amount of time, Billy is sentenced to serve a prison term of four years and two months for possession of hashish at the Samalclar State Prison. Billy and his father appear devastated while his defense lawyer argues that it is a good thing because the judges (sympathetic to Billy) turned down the prosecutor's request to convict Billy for smuggling or impose a life sentence in order to make an example of him.
Over the next several months, Billy slowly adjusts to prison life. He is also told about another prisoner named Rifki, who informs on other prisoners for unheard-of privileges and favors and has a special distaste for foreigners. Rifki also steals from his fellow inmates and seems to have an unlimited (for incarceration) supply of money to bribe the poorly paid guards. When Max offends Rifki, the informant kills Max's pet cat. Max tells Billy about the so-called 'midnight express' a code word meaning to escape from prison and how to do it.
After a little over two and a half years in the prison, Billy is informed that his case will be reviewed again. Thinking he's being let go early for good behavior, Billy rushes to meet with Stanley Daniels, the representative from the US ambassador's office in the Turkish capital city of Ankara. However, the representative has bad news; the High Court in the Turkish capital of Ankara has heard a different argument from the prosecutor who has appealed the four-year term verdict, and is seeking to charge Billy with smuggling hashish and make an example of him. The so-called double-jeopardy law of U.S. justice does not exist in Turkey. Any accused can be tried more then once for the same crime on appeal or should new evidence surface.
At another courtroom hearing, a distraught Billy rails against the three judges, the prosecutor, his own lawyers, the Turkish legal system, and the nation of Turkey itself. Speaking through a translator, with a mixture of anger and pity in his voice, the chief judge tells Billy that his hands are tied by Ankara and has no choice but to give him a life sentence. Billy is given a life sentence of 30 years, with time already served, for smuggling of hashish.
In 1974, Billy's friend, Erich, is granted parole and leaves the prison after serving around eight years.
Jimmy becomes convinced that he can escape the prison by going over the wall. Billy and Max refuse to join Jimmy, who is caught by the sadistic Hamidou and beaten so badly he suffers a hernia and loses a testicle. When Jimmy recovers and returns, he tells Billy and Max of another plan to escape; the stones used as walls in their section's kitchen are cemented in place with mortar that has weakened greatly in the dank conditions. Jimmy, Billy and Max discover two such stones and are able to remove them, finding a shaft behind them that leads to a system of flooded catacombs under the prison. The three of them spend several nights and hours searching for an escape route, however, it seems the Turks have long since blocked off every tunnel. The three give up and replace the stones, however, Rifki finds their secret in the kitchen and immediately tells Hamidou. Hamidou suspects Jimmy of being responsible and drags him off for punishment and Billy and Max figure out a revenge scheme: they find Rifki's stash of hidden money and destroy it by burning part and boiling the other part. In retaliation, Rifki frames Max for hashish possession. Hamidou has Max dragged off for punishment like Jimmy was. Billy goes berserk and savagely attacks Rifki in the washroom, chasing and beating the traitor until he bites out the man's tongue.
In 1975, Billy is sent to the prison's ward for the insane for several months where he wanders in a daze among the other disturbed and catatonic prisoners. His activities seem to consist solely of walking in a circle. One day a prisoner, named Ahmet, talks to him; his words seem restore some of Billy's sanity and he begins to walk in the opposite direction. Billy is visited by Susan who passes him a photo album and tells him it has a picture of his "good friend, Mr. Franklin, from the bank". Susan, feeling devastated at Billy's horribly bedraggled state, also opens her blouse so Billy can masturbate.
Billy returns to the sanatorium and inspects the book closely, finding several $50 bills hidden inside totaling around $2,000 in cash. Taking the money to Hamidou, he tries to bribe his longtime enemy to take him to the sanatorium that Jimmy had spoken about where the guards are more lax in their duties. Hamidou, chattering about being fed up with Billy, keeps the money and drags Billy to a large dressing room filled with guard uniforms and with pegs set into the walls. Hamidou beats Billy and attempts to rape him when Billy suddenly rushes Hamidou and pushes him forcefully backwards. Hamidou, flailing and trying to regain his footing, slams into the wall, driving a clothes peg into the back of his head, dying instantly. For a short time, Billy considers shooting the dead man with his sidearm but decides not to.
He dresses himself in a guard's uniform and reclaiming his money, walks through the prison unnoticed to the front door. As he walks down the stairs, another guard stops him and throws him the keys to the door telling him (in Turkish) to remember to lock up when he checks out. Billy walks out to the street, slowing down only briefly when a police jeep rushes past him. He runs away, the frame freezing on him as he takes a victorious leap. A title card tells us that on the night of October 4, 1975, Billy was able to cross the Turkish border into Greece and flew home to the United States three weeks later. The final shots of the film before the closing credits show Billy reuniting with his family and Susan.