ODESA, Ukraine — Their love story was only a month old when the Russian army smashed its way into their home city of Mariupol, in eastern Ukraine, two years ago and tore them apart.

Sofia Malina fled with her mother and grandfather to a cottage on the outskirts of the city and eventually managed to escape to Germany. Her soul mate, Polina Muzhychkova, hid with her parents in basements through weeks of bombardment and then fled with her mother to the Crimean Peninsula, a part of Ukraine annexed by Russia 10 years ago.

The two women — Malina was 19 at the time, Muzhychkova 17 — survived the terrifying violence of the Russian invasion, but ended up on opposite sides of the front line. It took two years, careful planning and huge leaps of faith for them to find a way to be together again.

Malina, a pro-Ukraine LGBTQ activist, traveled back into Russia and then Crimea, where she reunited with Muzhychkova. Together, they planned their escape for a year from what was a repressive and intolerant Russian-controlled society. In April, they fled through Russia and crossed into Ukraine, planning eventually to make their way to Germany.

They arrived late one night with their cat, Ozzy, at a Ukrainian police post in the eastern city of Sumy, nervous and exhausted and complaining that Russian police at the border crossing had physically abused them.

“They grabbed me by the hair and punched me in the face,” Malina said.

Four Russian border officials interrogated her, she said, asking what she thought of Russia and of President Vladimir Putin. They asked why she was going to Ukraine and whether she supported LGBTQ rights.

“Why do you dye your hair? Are you lesbian?” one demanded. “I was denying it,” Malina said. Then one of the men struck her.

Held in an interrogation room for an hour and a half, Malina said she came out to find Muzhychkova, weeping and shaking, unable to talk after being subjected to similar abuse.

The Russian Defense Ministry media office did not respond to a request for comment about the incident.

It was the last ordeal in a traumatic two years during which both women narrowly escaped with their lives and experienced horrors that still haunt them.

But they also emerged with a sure sense of what they want in life: to live together in freedom. They both were keen to share their stories in several lengthy interviews in Odesa, where they worked as baristas this summer.

The two became friends after Malina saw Muzhychkova outside the Drama Theater in Mariupol in the summer before the war. Muzhychkova was celebrating her high school graduation, lying on the lawn, her face in the grass, her mop of dyed red hair visible. “I thought we must get to know each other,” Malina recalled.

She began to follow Muzhychkova on social media, where she posted her drawings, but it took months before Malina dared to strike up a conversation. In January 2022, they met up for the first time and became inseparable. Both were struggling with mental health issues, and they bonded immediately.

“We realized I was screwed up and she was screwed up. So we suited each other,” Muzhychkova said. “Then, unfortunately, the war started.”

More than any other place in Ukraine, Mariupol, a port city of 500,000 inhabitants, came to symbolize the brutality of the Russian invasion. During an 80-day siege, Russian tanks, warplanes and artillery smashed their way through the city, destroying homes and killing thousands of civilians. The Drama Theater where the couple first met was badly damaged in an airstrike.

The outskirts of the city where Malina and her family were sheltering were soon overrun by Russian troops. Malina saw their neighbor killed when a Russian armored vehicle opened fire on him as he came out of his front door.

The Russian soldiers detained her with her mother and dozens of other women and girls in a basement for four days. Then without explanation they were released, frightened but unharmed, and managed to make their escape through dozens of Russian checkpoints to Ukrainian-held territory.

Muzhychkova stayed in Mariupol for two months, sheltering with her parents in the basement of their apartment building, without heating or electricity and with dwindling supplies of food and water.

In April, when the fighting eased, Muzhychkova and her mother escaped to Sevastopol in Crimea, where Muzhychkova’s godmother lived. She left, feeling an overwhelming sense of emptiness. Mariupol, her home for all her life, was “in ashes, a dead place,” she said.

Malina and Muzhychkova kept in touch, chatting endlessly online. Malina was urging her friend to leave, but Muzhychkova was hesitant.

“I realized I could not get her out from Germany,” Malina said. So one day in April 2023, she got on a bus and traveled into Russia, ostensibly to visit her estranged father in Moscow, and then journeyed to Crimea. A friend recorded their meeting in Crimea as Malina arrived with a bouquet of red roses, and she and Muzhychkova hugged tightly on the street.

In Crimea, she found a job in a cafe and a cheap apartment, and Muzhychkova moved in with her. The two kept their views to themselves, even from family, but they planned to save money and make their escape together. They both obtained Russian passports because they were required for working or studying in Crimea.

The two visited Mariupol in July 2023 to obtain identity and property documents and stayed with Muzhychkova’s father, who was living in a borrowed apartment and trying to resurrect his business supplying goods to restaurants. Much of the city was unrecognizable, Muzhychkova said.

“My father was trying to say the city was being rebuilt and people were coming back,” she said, but she felt he was devastated. “You are an adult man, you have a business, a life, a family and a home, and suddenly at 50 it is all scrapped,” she said.

Muzhychkova never told her parents of the nature of her relationship with Malina or of her plans to leave Crimea. They saw her future in Russia, but she did not.

So one day in April, without telling anyone, the two set off on the 48-hour bus journey through Russia to Ukraine. When they arrived in Rostov, in southern Russia, Muzhychkova sent messages to family members saying she had left.

“It was extraordinarily scary and painful to leave because of my parents,” she said. “It does not matter who they are; they did a lot for me.”

“But because they support Russia,” she said, “I do not accept that, and I decided to leave.”