Over the next two months prisoners convicted of nonpolitical criminal offenses could also benefit from the amnesty law, which could free about 3,000 inmates and reduce the sentences of 14,000 more.

Mr. Ivanishvili’s political coalition, Georgian Dream, won parliamentary elections last October, setting the stage for a power struggle between the prime minister and the president. Mr. Saakashvili, whose popularity had been sliding as he nears the end of his second term in office, is scheduled to step down in October after a presidential election. Term limits bar him from running again.

But the two will share power until then, and the amnesty law is an early test of how this arrangement will work.

Mr. Meskhidze, walking out of prison Sunday, said he had not seen his family since 2010, when he and 12 other people were arrested and convicted of spying for Russia. He said that he was innocent, and that the whole case had been fabricated by Mr. Saakashvili’s prosecutors because they wanted to “promote hatred” for Russia in Georgia. The two countries fought a brief war in 2008 and have not re-established diplomatic relations after severing them during the conflict.

“For two years and three months I was trying to understand why this happened to me,” Mr. Meskhidze said. “I never did anything bad to my beloved country and was always an honest soldier. It was just bad luck for me.”