The swap follows last month's release of Ukrainian pilot Nadiya Savchenko after two years in a Russian prison.
Savchenko was swapped for two Russians convicted of fighting in eastern Ukraine.
In Tuesday's exchange, Russia's President Vladimir Putin pardoned Gennady Afanasyev, who was convicted on charges of sabotage, and Yuri Soloshenko, convicted on espionage charges.
Ukrainian President Petro Poroshenko welcomed them in Kiev after their return.
Ukraine, in its turn, freed two imprisoned pro-Russia Ukrainian journalists from Odessa, Elena Glishchinskaya and Vitaly Didenko. They were flown to Moscow. Glishchinskaya traveled with her newborn baby.