Russia has taken part in a carefully co-ordinated spy swap with Norway and Lithuania, in a deal that required the Lithuanians to change their laws.
It took place at Lithuania's southern border with Russia's Kaliningrad exclave and involved two Russians, a Norwegian and two Lithuanians.
The three countries have been working on the operation for weeks.
The best known of the five men is Frode Berg, a Norwegian ex-border guard arrested in Moscow in 2017.
His case became a cause celebre in Norway after he was found with naval documents handed to him by a former Russian policeman.
Norway's Prime Minister Erna Solberg told a news conference that Norwegian authorities had worked hard to bring Berg home from the start and a solution was finally found with the help of Lithuania. "I am happy to tell you that Frode Berg is now a free man," she said, adding that she had spoken to him and he would return home as soon as possible after two difficult years.
Berg's daughter said she was overjoyed he was free. She was waiting in Oslo for his return.
The two Russians, Nikolai Filipchenko and Sergei Moisejenko, were jailed in Lithuania two years ago.
The Lithuanians, Yevgeny Mataitis and Aristidas Tamosaitis, were jailed in 2016. Lithuania is a former Soviet republic but since independence in 1990 the Baltic state has joined the EU and Nato.
Confirmation of the swap came from President Gitanas Nauseda and the head of Lithuania's SSD state security. "I am happy that their loved ones finally have a chance to see their husbands, fathers and sons," said Mr Nauseda in a statement.
The Norwegian prime minister said the Lithuanians had been present at the time of the swap and she paid tribute to President Nauseda's "personal courage" in securing the release.
How did the exchange happen?
Darius Jauniskis, the head of Lithuanian intelligence, said the swap had taken place at one of the country's border control posts and he paid tribute to the intelligence officers who had planned and carried out the operation.
Berg's lawyer, Brynjulf Risnes, revealed on Twitter that the Norwegian was "finally free" after crossing from Kaliningrad. "I'm in Lithuania and waiting to meet him soon," he added.
The transfer took place at midday (10:00 GMT), said Mr Jauniskis. Berg was taken to the Norwegian embassy in Vilnius and the foreign ministry in Oslo said he would soon return to Norway to be reunited with his family.
The two Lithuanians were being returned to their families, the president said.
How the swap was prepared
Talk of a three-way exchange first surfaced last month when Moscow's official pardons commission recommended the Norwegian for pardon. Russian Foreign Minister Sergei Lavrov visited Berg's hometown of Kirkenes in northern Norway for a ceremony and promised a decision would come soon.
The process was then put on hold for several weeks for Lithuania's parliament to change the criminal code to allow the president to pardon the two Russian spies.
Lithuania's state defence council, which is chaired by the president, then approved the swap last week, according to Baltic News Service.
Early on Friday the Lithuanian president announced the two men had been pardoned. It was a signal that the operation was under way and the head of Russia's SVR foreign intelligence service, Sergei Naryshkin, said "reciprocal measures" would take place.
Who are the five involved?
Russians: Nikolai Filipchenko - FSB security service agent was given 10 years for trying to recruit senior Lithuanians; Sergei Moisejenko was given 10 years for recruiting a Lithuanian army officer serving at Siauliai military base.
Norwegian: Frode Berg - retired border guard admitted acting as a courier for Norwegian intelligence but denied spying.
Lithuanians: Ex-naval officer Yevgeny Mataitis is a dual Russian-Lithuanian citizen who served in the Russian exclave of Kaliningrad. He was given 13 years for selling secrets to Lithuanian intelligence.
Where do spy swaps take place?
During the Cold War, exchanges took place at the Glienicke Bridge between East Germany and West Berlin.
Since the end of the Cold War, spy swaps have become rare events. The last big one, in 2010, took place at Vienna airport, when 10 Russian agents were flown in from the US and swapped for four prisoners convicted in Russia.
But there have been smaller swaps on a bridge between Russia and Estonia. In 2015, an Estonian security official who the EU said was abducted by Russia was swapped for a man imprisoned in Estonia for spying for Moscow.
When the US released convicted Russian agent Maria Butina last month, she was deported straight back to Moscow.