On Thursday at 6 p.m., Eynulla Fatullayev lay on his prison bunk ready for his nightly battle with despair, a young newspaper editor growing old midway through an 8½ -year sentence for writing articles that the Azerbaijani government disliked.

Fatullayev knew that media and human rights groups around the world — and even the U.S. government — were fighting for him, but he had little reason to hope for justice. When told to pick up his things and report to the warden, he had no idea what to expect — they could hardly move him to a prison worse than Strict Regime Penal Colony No. 1.

Moments later, the warden told him he had been pardoned by the president, Ilham Aliyev. Unbelievably, Fatullayev was free. The warden did not let him call his parents — no crowds should gather to cheer him — but personally drove him home. After more than four years of cold and deprivation, Fatullayev left prison in a Mercedes Benz.

“I only wanted to run a professional newspaper,” said Fatullayev, who entered prison at age 29, dark-haired and youthful-looking, and emerged at 34, balding, graying and paunchy from lack of exercise.

“It was a terrible experience,” he said, his eyes red and blinking, still adjusting to normal light two days after his release. “I spent a lot of time in dark rooms.”

Fatullayev said he was moved to different prisons, often held in solitary confinement and frequently ill. In standard barracks, 100 to a room, prisoners were awakened at 6 a.m. and sent out into a small yard where they stayed until 10 p.m., with no roof overhead and nothing to sit on. In solitary, where he spent three, five and 10 days at a time, a wooden frame without a mattress was pulled down from the wall at 9 p.m. and folded up at 5 a.m. The single window had no glass.

A long list of media and human rights organizations appealed on his behalf. The Council of Europe’s human rights commissioner visited him three times, Fatullayev said, and eventually won him the right to read newspapers. The U.S. State Department publicly called for his release. Both President Obama and Secretary of State Hillary Rodham Clinton, he was told, brought his case up with Aliyev.

After his editor at the Monitor newspaper was killed in 2005, Fatullayev started two newspapers of his own, one in Russian and one in Azerbaijani. He first got into trouble describing a police gang of criminals, led by a deputy minister who was ultimately jailed. Fatullayev wrote that the interior minister was responsible, as well, because he was in charge. The minister won a defamation suit, and Fatullayev was fined, given a suspended jail sentence and the kind of government attention meant to keep him quiet.

He was arrested in April 2007. “The government suddenly remembered I had visited Nagorno-Karabakh in 2005,” he said, referring to the territory that is the subject of an unresolved dispute between Azerbaijan and Armenia. Fatullayev’s interviews had produced an account of a well-known massacre there in 1992 during Azerbaijan’s six-year war with Armenia. He was jailed for 2½ years for insulting the honor and dignity of Azerbaijani refugees from the territory.

Another article suggested that if the United States and Iran ever went to war, Iran could attack Azerbaijan. He was charged with terrorism. An article about the prevalence of tribalism in national politics — many officials are from the president’s home region — brought him ethnic hatred charges.

“Six months later, the tax inspectorate launched an investigation into my newspapers,” he said. “I was charged with evading taxes. I got an additional three months.” His newspapers were closed, and he had a total of 8½ years of prison ahead of him.

In April 2010, the European Court of Human Rights ruled he had been denied a fair trial and ordered his release. “The government was very irritated,” Fatullayev said. Before the ruling could be acted upon, he was accused of possessing heroin in prison and given a new sentence of 2½ years.

From March 2 to April 2, he was in solitary at prison No. 1. “There were great rats,” he said. “At night I could see them on my body.”

Both his mother, 60, and his father, 61, lost their jobs because of him. Without help from the Committee to Protect Journalists, Amnesty International, the Open Society Institute and others, he said, his family would not have survived.

He turned to the late Alexander Solzhenitsyn. “Every prisoner had a book,” he said. “One might have the Koran, another the Bible. Mine was ‘The Gulag Archipelago.’ When I lost hope, I opened Solzhenitsyn and I said to myself — I talked to myself every night — ‘He was in a far worse place and kept his will. You can keep yours.’ ”

Now, in freedom, he is trying to figure out how to live again.

“I am thinking, how can I continue my journalism? The first way leads me to prison. The second may lead me to the cemetery. What do I do?

“Right now,” he added, “I can only say that I’m trying to understand freedom. It’s a miracle for me, and I’m trying to understand it.”