A Ukrainian court on Thursday unexpectedly released a key witness in the case of the 2014 downing of Malaysia Airlines Flight 17, just minutes before Russian President Vladimir Putin said he was optimistic about an impending prisoner swap with Ukraine.

Russia and Ukraine, which remain deadlocked over Russia's 2014 annexation of Ukraine's Crimean peninsula and the separatist-controlled east, have been discussing a major prisoner exchange that could release dozens of Russians and Ukrainians kept in custody in the two countries.

The appeals court in the capital Kyiv ordered the release of Volodymyr Tsemakh from custody on recognizance, pending further investigation.

THREE RUSSIANS, ONE UKRAINIAN TO BE TRIED FOR MURDER IN MH17 TRIAL

Tsemakh, who was the commander of the separatists' air defense in the area where the MH17 flight was shot down five years ago, was abducted by Ukrainian security services earlier this year and taken across the frontline to Kyiv.

Shortly after Tsemakh was released on Thursday, Putin spoke about the impending prisoner exchange at a conference in Russia's Far East, saying that the negotiations are now in their final stages.

"I think (the swap) will be fairly big," he said in televised remarks, adding that it would be a "good step" to improve Russia's ties with Ukraine.

Later that day, Putin met with Ukrainian politician Viktor Medvedchuk who has negotiated prisoner swaps with Russia before.

Putin did not give any timeline for the impending exchange but told Medvedchuk that Russian and Ukrainian authorities would make the announcement soon.

Unconfirmed reports have suggested that Tsemakh is on the list of prisoners that Russia wants exchanged in return for freeing several Ukrainians jailed in Russia, including 24 sailors captured off Crimea in November.

Among others who could be going home is a Russian journalist who was released by a Kyiv court on parole last week, and a handful of Ukrainian prisoners, including film director Oleg Sentsov, who have recently been taken from their Russian prison colonies to a temporary facility in Moscow.

RUSSIAN MILITARY MISSILE DOWNED MH17 PASSENGER JET IN 2014, INVESTIGATORS SAY

Responding to the reports that Tsemakh might be sent to Russia, Dutch prosecutors investigating the MH17 downing which killed all 298 people on board said earlier this week they would like to question him.

Dozens of Ukrainian lawmakers signed a petition to President Volodymyr Zelenskiy earlier this week, urging him not to hand Tsemakh over to Russia.

All 298 passengers and crew on board the flight from Amsterdam to Kuala Lumpur were killed on July 17, 2014, when a missile shattered the Boeing 777 in midair over the rebel-controlled area, sending debris and bodies raining down onto farms and fields of sunflowers.

Overwhelming evidence has pointed to Russia supplying both funds and weapons to the rebels. In June, four people, including a prominent separatist commander, were charged in the Netherlands with murder over the plane's downing.

The investigation team, made up of detectives and prosecutors from the Netherlands, Malaysia, Australia, Belgium and Ukraine, last year said that it was convinced that the Buk missile system used to shoot down flight MH17 came from a Russian army brigade.

CLICK HERE TO GET THE FOX NEWS APP

Russia has always denied responsibility for shooting down the flight and claimed last year that the Buk missile came from Ukrainian army arsenals. The Netherlands and Australia have said they hold Moscow responsible for providing the Buk missile system used in the downing.