An Islamic State militant distributes gifts to students at a school in Mosul, Iraq, in January 2015. (Militant Web site via AP)

For civilians leaving the Islamic State-ruled city of Mosul, the ending can be deadly.

Residents say the northern Iraqi city has become a prison since the militants seized it in June 2014 and imposed brutal control. The Iraqi capital, Baghdad, once a drive of about six hours down the highway, may as well be a foreign country.

One man’s story of escape sheds light on just how hard it has become to get out. In the end, the man — a former taxi driver in his late 20s — relied on smugglers to cross through Syria to Turkey to fly to Baghdad: a 1,500-mile journey to get to a place just 250 miles away.

Smuggling routes have become the only way out for those trapped in Mosul, the capital of Islamic State territory in Iraq. As a growing number of Iraqis and hundreds of thousands of Syrians flee to Europe, the Islamic State is trying to prevent an exodus from its territory by tightening controls and releasing videos disparaging those who leave.

Economic crisis in its cities after the central government in Baghdad cut off salaries has also spurred desperate civilians to try to get out.

Map: What a year of Islamic State terror looks like

Keeping civilians in its territory, however, is an imperative for the group, which draws considerable revenue from taxing them. As well as generating income, the civilians could be used as human shields in the case of an assault on the city, while their departure tears at the group’s narrative that its self-proclaimed caliphate is a haven for the world’s Muslims.

Residents used to be granted permission to leave for medical or business reasons, but that is now said to be rare. Some, mostly elderly, residents were allowed to leave on pilgrimage to Saudi Arabia in September, on the condition that they leave their property deeds as a guarantee, but trying to leave without permission can result in execution, residents said.

Many take the risk anyway. Life in Mosul had become intolerable, the former taxi driver said. Public punishments occur regularly. People suspected of being gay are thrown off buildings to their deaths. The hands of accused thieves are cut off and adulterers stoned. Smokers are lashed.

“I was fed up,” he said, speaking on the condition that his name not be used because his relatives remain in Mosul, and he fears they could be punished if the Islamic State finds out he has left. “You feel nervous all the time. There are so many rules.”

Since the central government stopped paying state employees in Mosul this year, one of the few sources of income for civilians has dried up. Teachers and doctors who remain are forced to keep working without pay. Jobs are hard to come by, and prices for basic goods have climbed. Meanwhile, the Islamic State’s rule has become steadily more oppressive.

“It’s a big prison now,” said Suha Oda, a social activist who used to live in Mosul and monitors the situation there. She described the cutting off of salaries as a “death blow” to the civilians left in the city, who have long given up hope of a military offensive in the near future to free Mosul.

“They feel like the government [in Baghdad] has abandoned them,” she said.

She said that recently, a friend and her husband and child were caught trying to leave. “They were sold out by the driver that they’d paid to get them out,” she said.

The three were detained and are back in their home in Mosul but live in fear of further punishment. A couple who tried to leave a month earlier were executed, Oda said.

The former taxi driver said he had wanted to leave Mosul earlier but stayed to look after a sick relative. He then heard that a friend of a friend had a relative in the Islamic State who was taking money on the side to get people out. He paid just under $1,000, putting himself in the hands of a chain of smugglers with little idea of where he would be taken.

“It wasn’t easy, because if they found out I was planning to leave, I would be killed,” he said. “If I sought out the wrong man or someone informed on me, I’d be taken immediately to be executed. It’s forbidden to leave Islamic State territory for infidel territory.”

As a member of the Islamic State apparatus, his smuggler could easily navigate checkpoints. There were initially three people trying to leave in the group. But when they reached a safe house outside of Mosul, two families joined, taking the total to about 11.

After five nights there, they were smuggled to Turkey, through Raqqa, the Islamic State’s stronghold in Syria.

“We didn’t know where we were. It was my first time outside of Iraq,” he said.

But traversing neighboring Syria is one of the few ways out of the Iraqi city. Earlier in the summer, one of the man’s relatives left by road to Baghdad through Iraq’s western province of Anbar, but that route involves crossing active front lines, and Mosul residents, virtually all of whom are Sunni Muslims, say they also fear running into Shiite militias on the way.

“It’s dangerous. You’re on open land,” the former taxi driver said. “There’s bombing. Many people get killed that way.”

After leaving Raqqa, he was passed on to a new set of smugglers to be taken across the border into Turkey, by which time the group being smuggled had swelled to 50 — mostly Syrians desperate to leave their country. The first time they tried to cross into Turkey, authorities at the border turned them back.

The second time, walking in the footsteps of their smuggler through a minefield, they made it. The Iraqi man said that getting to Turkey from Mosul had taken eight days. He then traveled to Ankara, the Turkish capital, to turn himself in at the Iraqi consulate. Then he waited more than a month to receive a travel document to be able to board a flight back into Iraq. He had been given a “very hard time,” he said.

Iraqi Sunnis from Mosul complain of widespread discrimination by mostly Shiite Iraqi state officials, who view them with suspicion.

When the man from Mosul finally arrived in Baghdad in late September, he was immediately arrested. Before being bailed, he was detained for eight days and charged with leaving the country illegally.

“To get to my homeland after all that and be arrested,” he said. “It’s like they don’t see us as Iraqi.”

Read more:

New U.N. report says world’s refugee crisis is worse than anyone expected

The unbelievable damage Islamic State has done to ancient sites in Iraq and Syria