MOSCOW -- On July 18, 2017, Gaylen Grandstaff received a package that changed his life.

Grandstaff, a 52-year-old former firefighter from Texas, had been living for the past seven years in Moscow with his Russian wife, Anna. The couple taught English and lived quietly in a small apartment in a traffic-choked northern neighborhood.

For years, Grandstaff had suffered from Crohn's disease and used peptides to treat the ailment. Weeks before, he had ordered the pills using the Chinese site, Alibaba. In addition to his usual order for the peptides, he also bought a $10 bottle of metal cleaner that he claims was pushed on him by the man who sold him the pills.

Minutes after the package arrived that evening, there was banging on the Grandstaffs' door. They opened it to find four Russian customs officials, along with an attorney, witnesses and a translator.

Crowding into the two-room apartment, the agents told the Grandstaffs the cleaner Gaylen had ordered contained a banned narcotic substance and that he was under arrest for drug smuggling.

"When they first told us, we were -- I mean we just couldn't believe it," said Anna Grandstaff.

Around 4 a.m., Gaylen Grandstaff was taken to jail. Two days later, he was brought before a judge and formally charged with smuggling a psychotropic substance in a large quantity, and ordered held in pretrial detention.

From that moment, he was in the hands of the Russian criminal justice system, kept in Moscow jails for almost two years while on trial. The charge against him carried a maximum sentence of 20 years in prison.

For the next 608 days, Grandstaff would endure life in jail and a harrowing separation from his wife, whom he called "ladybug." He would also give a glimpse into a world that most Americans will never see by illustrating his time in detention through vivid drawings of a cartoon bear, based on his wife's nickname for him, which he depicted living his Russian prison experiences. This is also the story of how against the odds he was eventually, unexpectedly, released.

Grandstaff's case is not a high-profile spy caper or a political show trial, like those that the Russian court system is better known for abroad.

Instead, it illustrates a side of the Russian justice system that affects far more ordinary Russians -- low-level criminal trials skewed to ensure not justice, but conviction, and where those accused often spend lengthy time in pretrial jail even while still nominally innocent.

Inherited from the Soviet Union, where the state's actions were treated as infallible, Russia has an almost 100% conviction rate. In 2018, only 0.43% of cases ended with acquittal, according to an analysis by Proekt.media of statistics from Russia's Supreme Court. It's a product of a judicial system where power lies overwhelmingly with prosecutors, where manufacturing evidence is routine, where defendants are presumed guilty.

Grandstaff had also fallen afoul of Russia's draconian drug laws and seemed to have become one of tens of thousands of suspected fabricated drugs cases, which have recently become a lightning rod for popular dissent in the country.

"It's a system that's out of control. I'm not the only one. They prosecute anyone who is accused, and they do not, they absolutely do not, listen to the facts," Grandstaff said, speaking through the bars of a courtroom cage in November 2018.

'They said this is not what we were looking for'

Police said the banned substance contained in the cleaning product was gamma-butyrolactone or GBL. It's a common solvent, legally used as an industrial cleaner but also a precursor to the more potent drug, gamma-hydroxybutyric acid or GHB, a party drug associated with "date-rape" drugging. Both substances are also sometimes taken as a muscle-growth stimulant by bodybuilders.

Because of its closeness to GHB and its own narcotic effects, in the U.S. and many other countries GBL is a controlled substance -- in Russia it's banned.

Grandstaff, though, said he had no way of knowing the cleaner contained GBL. The seller, he said, had offered it when he was ordering the legal peptides for his Crohn's disease, describing it as a waterless solvent that he would throw in for $15. Grandstaff said he initially declined. But after the seller lowered the price to $10, Grandstaff, remembering he had a metal still in which he brewed alcohol that could use a cleaning, said he decided on a whim to buy it.

The Grandstaffs thought the police would see the arrest as an obvious mistake.

"We weren't very stressed because they assured us that he will be released in two days, that no one is going to take this seriously, was not what they came looking for," Anna Grandstaff said.

Instead the police brought a particularly harsh charge, one intended for large-scale drug smugglers, and recommended Grandstaff be held in jail while they investigated.

'Psychological solitary confinement'

On his first night in jail, Grandstaff was placed with 18 men in a cell that was designed for six. There weren't enough beds, so he slept on the floor. It was the first of many cells in different detention centers. Other cells had open toilets in the floor, there was trash in the corridors as well as rats.

"I had no idea that conditions could be like that. Not today," Grandstaff said. "You see these kinds of things in movies -- you see Russian prisons as these dark, dank places that are you know like a dungeon. That's a very good way to describe much of what I saw."

Grandstaff was held mainly in Moscow's Detention Center 3, a forbidding, crumbling building in an industrial zone. Mostly, he would share cells with one or two other prisoners. Inmates were kept in their cells the vast majority of the time, he said. He was allowed to walk in the prison yard on average only once every three days. Showers were allowed at most once a week, but at times Grandstaff said he went more than a month without one.

For food, prisoners depend on relatives for deliveries, including drinking water, or to help pay for meals. A missed delivery would mean no food for 24 hours.

Grandstaff spoke little Russian, doubling his isolation. His foreignness made him a novelty for guards and other inmates, who harassed him. In 2016, Russia's justice minister told the BBC there were only 73 Americans in all of Russia's prisons.

"I am in psychological solitary confinement," Grandstaff wrote to his wife.

In summer 2018, Grandstaff was attacked by a group of around 25 inmates that decided he was a snitch. On another occasion, he claims he fell from a prison transport, banging his head on concrete and injuring his neck. He said he spent almost three weeks without medical attention before being hospitalized. Grandstaff, still suffering from Crohn's, also accused the prison of ignoring his requests for medical examination for weeks. One day, Anna said, guards forced Grandstaff to strip naked outside and hop on one leg, while they taunted him about President Donald Trump.

Grandstaff responded by regularly filing complaints.

"I guess because he's an American, and maybe he's used to fighting for his rights and he's a little more outspoken, they don't like that," Anna said. His treatment eventually improved after he established a relationship with the warden, to whom he would report mistreatment by guards.

Anna's life meanwhile was taken up with tasks to make Gaylen's incarceration bearable. The two had met in Myrtle Beach, South Carolina, in 2007. Four years later, they moved back to Russia to be closer to Anna's parents.

Anna was permitted to visit her husband twice a month. He was allowed to send letters, but only in Russian. One day, to cheer Anna up, he drew her a bear.

Before his arrest, "bear" and "ladybug" had just been their pet names for each other, but over time, Grandstaff began to use the bear to convey his prison experiences to his wife. There were bears sleeping in leaky cells or skating on the frozen ground of the prison yard. At home, Anna made a life-size cutout of a bear in a tuxedo her husband had drawn for their anniversary and placed it in the living room.

"I don't want to remove it," she said, a little sheepishly. "It reminds me of him."

'Absurd in itself'

The investigation against Grandstaff seemed to show signs that parts of it were being manufactured to support the claim he had known what he was buying. Police didn't collect some basic evidence: court documents show they never searched his computer.

Investigators initially suggested Grandstaff had bought the GBL to sell, but when it became clear the evidence wouldn't support that theory, they accused him instead of buying the solvent for bodybuilding.

Needing to paint Grandstaff as a fitness obsessive, investigators appeared to use crude tactics to do so.

A friend of Grandstaff's, who had been a semi-professional female power-lifter, accused investigators of distorting her testimony to suggest Grandstaff also did power-lifting. Prosecutors tried to claim the legal peptides Grandstaff had bought for his Crohn's disease were proof he used steroids, but they refused to carry out tests that would have shown if they could be used for that purpose, according to his lawyer.

Some of the prosecution's efforts appeared farcical to observers. The prosecution summoned as an expert witness the head of a weightlifters union from a small town outside Moscow who had no connection to Grandstaff. The heavily built man was called to provide expert testimony on illegal steroids, but at the hearing instead kept repeating he was "not an expert" and gave vague descriptions of using peptides.

"This case, I have the impression that it's in itself somehow absurd," said Eva Merkacheva, a veteran crime journalist at the newspaper Moskovsky Komsomolets, who also serves on Russia's prison oversight commission.

"They don't look for the facts," Grandstaff said. "They look for ways to support their theories."

Three of the prosecutors resigned over the course of the trial. Grandstaff said that one, the primary author of the indictment, had approached him before leaving to ask Grandstaff not to seek financial compensation from him for his role in the bringing the trial, which he implied he knew was wrong. ABC News was unable to reach the prosecutor, but a witness to the conversation confirmed hearing the exchange.

Russia's interior ministry and the prosecutor's office declined to answer questions on the case. Russia's federal penitentiary service and the department tasked with prisoners' court transport did not respond to ABC News' questions about Grandstaff's treatment.

The U.S. embassy sent a consular officer to monitor the case.

There appeared to be problems with Grandstaff's version of events, though. There was no recording of his conversation with the seller and no way to show he had not known what he was buying. And in the indictment, prosecutors alleged that when they intercepted the package, the cleaner was packed in a manner typical of smuggling.

Grandstaff said he could not have known how the seller would send the cleaner, and his lawyer has argued police may have tampered with it.

Ultimately, even if Grandstaff had known what he was buying, the charge brought against him was excessively severe, experts said, given police accused him of intending to use it for personal fitness. He had also already spent well over a year and a half in jail, in grim conditions, without being convicted.

"I don't understand the cruelty of our investigators in this case," Merkacheva said, noting Grandstaff also would have been a first-time offender.

They need a result

Grandstaff's lawyer and other Russian legal experts said they believed the main driver in his case was likely one common to many Russian cases -- a desire to boost conviction quotas and a system that discourages any reversal once a person is charged. Prosecutors receive promotions for conviction numbers, while dropping charges is treated as a failure.

The culture of Russia's courts, experts said, is also heavily tilted in favor of the prosecution. Judges usually assume that if a case has reached court the person must be guilty. That presumption in turn means investigators often don't bother to present substantial evidence.

"For the overwhelming majority of Russian judges, the question of whether someone's guilty or not guilty doesn't matter," said Pavel Chikov, a veteran lawyer at Agora, an association specialized in human rights cases in Russia.

"They don't think in those categories. They think with the category by which they can examine the largest volume of cases. It's a conveyor belt," he said, adding that he thought the majority of Russia's defense lawyers could well go through their careers without ever winning an acquittal.

"They need a result," Grandstaff's lawyer, Anton Omelchenko, said of investigators. "And the result for them is only conviction."

Human rights lawyers have also described an epidemic of trumped-up drug cases in Russia. A Russian-language 2015 study by the St. Petersburg-based Institute for Problems of Legal Administration found there were tens of thousands of suspicious cases likely fabricated by police.

Police fabricate cases, experts said, to meet quotas and also to create opportunities for bribery. Using fabricated evidence to inflate a minor possession charge into large-scale trafficking is a frequent tactic, Chikov said, since police were rewarded more for getting serious convictions. Prominent Russian activists and journalists have also found themselves facing drug charges.

Recently, for many Russians, the issue has seemed to become emblematic of the cynical arbitrariness of the justice system under President Vladimir Putin. This month those feelings erupted spectacularly when a prominent investigative journalist, Ivan Golunov, was arrested in a crudely staged drug sting. The outcry that followed prompted an extraordinary reversal from the Russian authorities, who dropped the charges and fired the two police generals overseeing Golunov's case. Many observers called it unprecedented, and there are calls now for a campaign for legislation to prevent such cases.

"Any one of us can imagine ourselves becoming the main character in a crime story, and asking ourselves what will happen to me in such a situation?" Kirill Martynov, a journalist at the newspaper, Novaya Gazeta wrote afterward. "The answer is depressing. False evidence, dummy witnesses, a token trial and conviction. We all know dozens of examples of such lawlessness."

The two police generals fired over Golunov's arrest had overseen the departments also conducting Grandstaff's case -- Yuri Devyatkin, chief of Moscow's counter-narcotics division, and Andrey Puchkov, head of police for the city's western district.

A surprise twist

There was no sign, however, that Grandstaff's case would break the pattern.

"They will convict him," Anna said in November. "It's just a question of how long."

In March of this year, almost 600 days into Grandstaff's detention, the judge suddenly called a hearing to examine whether the prosecution's evidence was sufficient. It sounded like positive news, but Omelchenko was unsure.

On the day of the hearing, Grandstaff himself believed nothing would change.

"We've just moved from the big tent to the little tent" of the circus, he told his lawyer.

In court, the judge began reading the indictment again in full.

A court-appointed translator -- a young student -- was whispering the judge's words to Grandstaff. Suddenly, he looked up, surprised.

The judge was listing problems with the case, naming the inadequacies that Grandstaff's lawyers had raised for months. The police had never examined Grandstaff's computer, and they'd never established Grandstaff's interaction with the seller.

The missing evidence, the judge said, meant the accusations against Grandstaff were "unconfirmed and incomplete." In light of that, she said, she was returning the case to the prosecution for further investigation.

Then: "Grandstaff's detention is canceled and the court frees him in the courtroom."

The young translator stared saucer-eyed at the judge. A choking sob came from the benches -- two of Grandstaff's friends were weeping.

The guard unlocked the cage and for the first time Grandstaff walked out without handcuffs. His friends began to applaud. His lawyer walked to him and shook his hand.

"Do you agree with the judge?" the lawyer asked smiling.

"No, I think I had better stay in that cage," Grandstaff answered, laughing.

Grandstaff's release was so unexpected that his wife wasn't at the hearing. Convinced nothing would change, he had told to Anna to go on a trip with friends. Grandstaff called her from the court. She collapsed into tears.

"I was laughing and I was crying and jumping, and at the same time I just couldn't keep myself from walking around like a crazy person," Anna said afterward. "I can't even explain the feelings that I had."

Not free 'until my feet are back on American soil'

Why had Grandstaff become one of the few to avoid conviction?

He believed it was a combination of factors, in particular a rigorous defense by his lawyer, Omelchenko. Another decisive factor, he said he believed, had been the presence of the media -- among them ABC News, the Times of London and the BBC's Russian-language news service -- that repeatedly attended the trial.

"I think things like that began to open their eyes, to see that this all is not happening in secret like it would normally," Grandstaff said. "I think they began to realize that there was going to be -- inevitably -- there was going to be some accountability."

Grandstaff is now living back at in his apartment with Anna and trying to adapt to normal life. He keeps forgetting he is now allowed keys, he said, and still automatically put his hands behind his back to be cuffed before going through a door.

The case, formally, is still open. The prosecution has appealed the judge's ruling to send the case back for further investigation, and Grandstaff is now waiting for an appeals hearing that is still unscheduled. If the ruling is overturned, Grandstaff could be placed back in pretrial detention, though his lawyer believes that is unlikely.

"Every hour or so, I catch myself thinking, 'Oof, are they here? Are they going to come back? Is this really over?'" Anna said.

It means that Grandstaff is now effectively in limbo. Allowed to move freely around Moscow and, in theory, to work, he is not permitted to leave Russia while the case is still open. Though the Grandstaffs would like to return to the U.S., for now they're trapped in Russia. The prosecution has given no indication when an appeal hearing could happen, and Omelchenko said it's still possible the case could be left open for months, even years.

"This won't be over," Grandstaff said, "until my feet are back on American soil."

In the meantime, he's been working on a new drawing: It's a bear holding up a pair of handcuffs, now unlocked.