BERLIN — Germany and Russia, friends or foes for centuries but always near neighbors, have special, deep ties unlike those between the Kremlin and any other outside power. It was that relationship, and the select few people who enjoy access to it, that won freedom for Mikhail B. Khodorkovsky, the former oil billionaire suddenly granted clemency by President Vladimir V. Putin and flown to Berlin.

Chancellor Angela Merkel, a Russian speaker who has a matter-of-fact, occasionally frosty relationship with Mr. Putin, and her Social Democratic predecessor, Gerhard Schröder, who maintains warm ties to the Russian leader, both raised Mr. Khodorkovsky’s case with Mr. Putin over the decade of his imprisonment. But it was a highly experienced former foreign minister, Hans-Dietrich Genscher, who at the age of 86 achieved an agreement with Mr. Putin.

That involved two meetings between Mr. Genscher and Mr. Putin — one at Tegel airport in Berlin at the end of Mr. Putin’s first visit to Germany after he was re-elected in 2012, the other in Moscow, according to the German news media and statements from Mr. Genscher himself.

Ms. Merkel was kept informed of the secret talks, as was the top echelon of the German Embassy in Moscow, which expedited a visa for Mr. Khodorkovsky late last week once it became clear from Mr. Putin’s surprising talk of clemency on Thursday that it would be granted.