When Russian troops invaded his hometown in 2022, Ukrainian teenager Denys Kostev filmed TikTok videos cursing Vladimir Putin and praising Ukrainian courage.

A few months later, after he had been transferred against his will to Russian-held territory, he suddenly appeared in propaganda clips on Kremlin-controlled channels.

In one, the athletic, dark-haired boy stood in camouflage adorned with a Russian pro-war symbol and proclaimed that Putin would vanquish Ukraine.

“Victory will be ours!” he said.

Denys’s apparent transformation from Ukrainian patriot to Russian flag-waver looked like a triumph for Moscow. Here, it seemed, was living proof of Putin’s contention that Ukrainians are Russians at heart, and their dissent is a correctable defect.

Russia had removed Denys, an orphan, from the southern city of Kherson, making him one of more than 20,000 Ukrainian children that Kyiv says have been forcibly removed from occupied territory. Russia says it is protecting such children from war. Ukraine and its Western allies say it is committing a war crime and seeking to erase the children’s Ukrainian identities. The International Criminal Court has issued an arrest warrant for Putin over the forced transfers.

Only a few hundred children have returned. Denys’s relatives, living as refugees in Germany, campaigned to get him back. They wondered what had happened to the boy who had so enthusiastically championed Ukraine’s resistance. Had the Russians really turned him?

Their efforts to find out, and to reunite with him, took some unexpected—and perilous—turns. Kremlin officials have been frank about their quest to re-educate Ukrainian children, in a battle to win their minds. Denys’s relatives would find that his loquacious personality and knack for social media made him a target, plunging him into a world controlled by the chief executors of Putin’s plans for Ukraine: his feared security service. And when success seemed at hand, they discovered the hard reality of what Russia’s manipulation can do to the most vulnerable.

‘The perfect artist’

Denys had an unstable childhood. His parents, jailed on narcotics charges, were stripped of custody before his first birthday. In the years that followed, he was shuttled from one home to another. He stayed briefly with his half-brother Maksym Kostev and grandmother Svitlana Panchenko, and then in an orphanage, in a children’s home and with two separate foster families.

When Russia launched its full-scale invasion in February 2022, Denys was at a temporary care center for orphans and children from troubled homes. Russian tanks soon poured into Kherson, causing the walls of the building to shake.

The center’s director, Volodymyr Sahaydak, instructed the 52 children under his care to stay on the premises. He kept the curtains drawn and his wards entertained with ping pong and Ukrainian patriotic songs.

Denys, then aged 16, emerged as an ardent backer of Ukraine’s resistance. Contacted by a U.S. journalist, Sahaydak offered an interview with Denys, whom he called “the perfect artist” for his gift of the gab. In the interview with Scripps News, Denys thanked the U.S. for supporting Ukraine and spoke of the psychological strain of occupation.

When a mortar shell blew out several windows, Sahaydak began to fear for the children’s safety. Moscow’s troops had already transferred kids from other parts of Ukraine to Russia, so he contacted relatives who might shelter them.

Maksym—Denys’s half-brother, who was then 25—collected him on April 27. They stayed in an apartment with Panchenko, their grandmother, and Olha Hurulia, a family friend. Denys was glued to online updates about the Ukrainian army, listened to anti-Russian rap songs and sported a sticker on his cellphone case declaring “Putin is a dickhead,” Maksym recalled.

In May, Denys launched a TikTok channel where he posted videos cursing Putin and asserting Ukraine’s independence. In one clip he told Russians that only death awaited them in Ukraine. “Come,” he said. “We’ll teach you some history.”

Meanwhile, Moscow’s occupation was hardening. Russian gunmen raided Sahaydak’s care center, where most of the rooms were already empty. Panchenko and Hurulia were detained for hours by Russian troops who caught them hanging ribbons in the colors of Ukraine’s flag on a street.

Denys’s relatives decided it was time to leave, but they didn’t have a passport for him, and Sahaydak said the Russians took all the documents he had during the raid. So Panchenko left Denys with a friend outside the city while she, Maksym and Hurulia fled to Germany.

By fall, Denys was missing his friends. He enrolled in a culinary college in the city and moved into the dormitory. Days after he arrived, the new, Moscow-appointed college director interrupted class flanked by armed Russian troops, according to Liza Batsura, then a 16-year-old student who was also there. The director announced they would be taken to Russian-occupied Crimea for a two-week seaside break from the war. They were loaded on buses bound for a summer camp on the Black Sea called Druzhba, or Friendship.

‘Our historical choice’

Druzhba was one of several camps that housed the 2,000 Ukrainian children Moscow says it transferred from Kherson. Mornings began at 6 a.m. with physical exercise and a performance of the Russian national anthem, Liza recalled. There were games, excursions and classes on Russian history. Displaying Ukraine’s flag was banned.

In November, Ukrainian troops retook Kherson, but Denys and others weren’t allowed to return home. They were moved to another camp and then, in January 2023, sent to a college in Henichesk in the Russian-occupied southern tip of the Kherson region, according to children who went. There, Moscow’s top official in the region touted “unlimited opportunities” that awaited them under Russia.

Maria Lvova-Belova, Russia’s commissioner for children’s rights, visited in early February and handed the teenagers pieces of paper to write where in Russia they wanted to live and study.

Liza had lost hope her mother would come, and wrote “Moscow.” On another sheet, in Denys’s handwriting, she saw the name of a famed Russian military academy.

Russia documented its re-education of the children. Social-media posts by its military youth wing and reports on a Russian-run TV channel in Kherson show Denys handing out ribbons celebrating Russian military glory, learning to strip a Kalashnikov rifle and attending lectures depicting Ukraine as historically Russian land.

On Feb. 24, the one-year anniversary of Russia’s invasion, Denys stood draped in a Russian flag in a report on a state-run channel. “I want to serve in the army,” he said. “I’m ready to serve the Russian Federation.”

He appeared in dozens more clips over the following months, emerging as a face of Moscow’s propaganda drive and an apologist for its transfer of Ukrainian children. Dressed in military-style outfits, he thanked Russia for saving them from Ukrainian bombs, praised the courage of the Russian army and pledged loyalty to Putin. “We made our historical choice: to be together with Russia,” he said in one.

In private, however, Denys appeared torn. In text and audio messages he boasted to Maksym about payouts he was getting and parties with his friends from Kherson, but also told his relatives he missed them. “We told him not to despair, that everything would be fine,” Maksym said. They discussed ways Denys could leave, but he was skeptical, afraid the Russians wouldn’t let him. Russian authorities had stopped others who had tried.

Denys’s relatives got in touch with Save Ukraine, a Kyiv-based nonprofit that has helped get more than 200 Ukrainian children out of Russian-held areas. Moscow officially allows such children to be collected by their legal guardians or kin but Panchenko, 60, was bed-bound with heart problems. Maksym feared that if he went, the Russians would detain him as a suspected combatant.

Hurulia, the family friend who was sharing a room with Panchenko in refugee housing in Germany, agreed to go. Denys urged her to come. On May 12, she met in Kyiv with Save Ukraine representatives and the mothers of seven other children, including Liza. They took an overnight train to Poland, a bus to Belarus and a flight to Moscow. Hurulia carried a document from Kherson authorities listing her as Denys’s legal guardian.

Liza’s mother eventually made it to Henichesk and brought her home. Hurulia didn’t make it out of the Moscow airport. Upon landing late on May 16, she said, she was detained by plainclothes officers who confiscated her phone and interrogated her.

On May 18, a man woke Hurulia, handed her a statement to memorize and instructed her to record a video saying that she had been sent to retrieve children she didn’t know, she said. Russian state media later ran the clip as evidence that Kyiv was abducting Ukrainian kids.

Suddenly, Denys texted his family in Germany that he’d had a change of heart and wouldn’t leave. Maksym, unaware that Hurulia was in custody, pleaded with him. “Come on,” he wrote. “We made documents out for you, and arranged logistics. You’ve decided to stay?”

In an agitated audio message, Denys said the Russians were giving him money, promising him a spot at a Moscow school and an apartment. He was afraid of being conscripted into the Ukrainian army, he said, and reluctant to leave his friends. “I don’t want to go back, I don’t want to!” he shouted.

Hurulia was put on a flight to Minsk. Denys would be staying.

Plea for help

Denys changed his phone number and cut contact with his relatives. He took a Russian passport that made him eligible for conscription. He continued to film propaganda videos and, when he turned 18 in July 2023, launched an Instagram account.

The first photos showed him beside a statue in Moscow, a city he described as “vast and beautiful,” and smiling at a youth camp in Crimea organized by Lvova-Belova’s office, where he worked as a counselor for younger children brought from Ukraine.

In the fall he moved from Henichesk to a town near Moscow. The tone darkened. In one selfie he held a pellet gun to his neck.

In early December, he posted images of a cityscape bathed in red and yellow light. “My native Kherson,” Denys wrote in Russian, adding in Ukrainian: “I yearn for you.”

Three days later, Maksym received a message sent in Ukrainian from an unknown number. It came from his brother, the first message in seven months. Denys asked that Maksym pass his number on to his relatives.

When Maksym called 20 minutes later, Denys told him: I want to come home. And he opened up about what had really happened over the past year.

In a phone conversation with The Wall Street Journal the next day, he slowly and nervously told his story.

Around two weeks after he had arrived in Henichesk in January 2023, he said, a local official came to his dormitory and told him to step outside. Denys stepped into the street and saw a white Toyota SUV, its back door open. A man with a holstered pistol told him to get inside.

As they drove, the man and his driver flashed ID cards reading: Moscow Directorate of the Federal Security Service, or FSB. After a brief conversation they dropped him off, handing him 500 rubles ($6.50) and saying they’d be in touch.

Several days later his handlers told him to come to a local park and record a monologue about his time at the camp in Crimea. From then on, he said, “I became the main actor.” He was sent scripts to read, and often outfits to wear.

They also wanted him to work as an informant, and met him every few days in the Toyota to ask him to identify residents who backed Ukraine or to get Ukrainian military positions from acquaintances. Denys said he lied and obfuscated in order not to cause harm. The FSB didn’t respond to a request for comment.

When Hurulia was being held at the Moscow airport, Denys was summoned by his handlers, told she was in custody and shown the video she was forced to record. “They warned me that if I tried to protest or run away, I would be next,” he said. They told him to record the audio messages to Maksym. Denys complied, fearful of becoming another victim of disappearances that are routine in Russian-held territory.

After returning to his college dormitory, Denys couldn’t sleep. Consumed by shame, he missed classes and couldn’t bear to talk to relatives.

“I’ve been alone my whole life, with no family beside me,” he later said. “I understood that this was probably the end of my dream to live with my family.”

Escape

After he got back in touch with his family in December, Save Ukraine began working on a new plan to get Denys out, relying on a clandestine network of volunteers. His Russian passport was valid only for former Soviet states still within the FSB’s reach. He had changed his phone number and bank cards after moving to Moscow, and thought the FSB was no longer tracking him, but he couldn’t be sure. He had recently ignored a Russian military summons.

Denys was willing to take a chance. He packed his things and waited for Save Ukraine’s signal. “My dream is coming true,” he wrote in a text message to the Journal on Jan. 26. “I’m tired of living in solitude and deceit.” Friends he had arrived with in Russia had cut ties, he said, and he had quit his college after a conflict over stipend money. He wrote poems, including one about the mother he never knew.

By Feb. 6, Save Ukraine had clear instructions for Denys. That evening, he boarded an overnight train from Moscow to Minsk carrying his belongings in a sports bag. The train passed stations where Russian tanks idled on wagons. Too restless to sleep, Denys listened to rock music and thought about seeing his relatives and about the other children he first left Kherson with in the fall of 2022, most of whom remain in occupied Ukraine.

His trip to Minsk went smoothly as Belarus has no manned border with Russia. After two days arranging emergency travel documents with help from a Save Ukraine volunteer, he crossed on foot into Poland.

On Feb. 11, Denys boarded a bus bound for Germany, and his relatives prepared for a reunion. But at the border, at 3:30 a.m., he was taken off the bus and put in a police van, then held five hours for questioning. German officials rejected his travel documents and left him in Poland.

With his sports bag and a pouch carrying his Ukrainian travel document, Russian passport, German deportation order, and the equivalent of $50 in four currencies, Denys arrived at a town outside Warsaw the following evening with the help of Save Ukraine to stay with a Ukrainian family that had fled Mariupol after Russian forces razed and seized the city in 2022.

Over soup and pancakes, Denys told them the Russians aren’t as bad as they’re made out to be. That evening he echoed Moscow’s narratives, calling the Russian massacre in Bucha , a Kyiv suburb where Moscow’s troops slaughtered dozens of civilians, a fake tale spread by Ukraine. And he described the storied Ukrainian regiment that defended Mariupol as a bunch of Nazis. He said he now felt repulsion at the sight of the Ukrainian flag.

“He’s a classic example of what Russians can do to a still-developing child who has no one to defend him,” said Olha Yerokhina, a Save Ukraine spokeswoman who helped Denys. “They know he has a way with words, and that he’d speak about his time in Russia.”

Yerokhina wondered: Had he really escaped, or had he been allowed out by his handlers to spread their message?

Exhausted after his trip, Denys said in an interview that he had one wish: to live a normal, peaceful life with his relatives. He has applied for a new Ukrainian passport, and is appealing his deportation so he can finally reach Germany and the family that awaits him there.

Asked whether he felt Ukrainian or Russian, he shrugged.

“I’m a lost soul,” he said. “I always have been.”

Write to Matthew Luxmoore at matthew.luxmoore@wsj.com