The Russian Ministry of Defense has refused to acknowledge any ties to the two men, Capt. Yevgeny Yerofeyev and Sgt. Aleksandr Aleksandrov. The Ukrainian authorities placed them in a glass cage during a trial in Kiev, as examples of “the little green men,” a reference to the thousands of soldiers without insignia on their uniforms in Crimea and eastern Ukraine. A Ukrainian court in April sentenced both of the men to 14 years in prison on terrorism-related charges.

Mr. Poroshenko pardoned the pair, saying it was necessary to gain the return of a Ukrainian soldier from captivity.

Lieutenant Savchenko, a minor celebrity even before the war as the first woman to become a combat pilot in Ukraine, had been serving as an infantry soldier with a volunteer unit in the Luhansk region of eastern Ukraine when she was captured by rebel fighters. The Russian authorities say she then escaped from her captors and slipped into Russia posing as a refugee; Lieutenant Savchenko said she was taken to Russia as a prisoner of war.

A Russian court convicted her of serving as an artillery spotter and directing fire at a rebel checkpoint where a Russian television journalist and a sound technician were killed. She was sentenced to 22 years in prison for murder. Lieutenant Savchenko vigorously denied the charges and, at one point, went on a hunger strike to protest the trial, which she dismissed as a farce.

President Vladimir V. Putin of Russia went on television with the widow and a sister of the slain Russian journalists to say they had asked him to pardon Lieutenant Savchenko as a humanitarian gesture.

“I want to thank you for this position, and express hope, that the decision — dictated most of all by humanism — will lead to an easing of the tensions” in Ukraine, Mr. Putin said. He made no mention of Captain Yerofeyev and Sergeant Aleksandrov. Mr. Putin’s spokesman, Dmitri S. Peskov, referred to the pair as “citizens,” and said Mr. Putin had no plans to meet them.