MOSCOW — Ramil Safarov stepped uncertainly off the plane in his native Azerbaijan last Friday, returning home after spending eight years in a Hungarian prison for a gruesome murder. But it took only a few minutes for the celebrations to begin. There was a pardon, a new apartment, eight years of back pay, a promotion to the rank of major and the status of a national hero.

Mr. Safarov, 35, was already famous because of his crime. Eight years ago, carrying an ax, he crept into a dormitory room in Hungary where an Armenian serviceman, a fellow student in a NATO-sponsored English class, slept, and nearly decapitated him.

But now Mr. Safarov will almost certainly go down in history for the way he was freed, an episode people have started to call “The Safarov Affair.”

The backlash has embarrassed Hungary, which agreed to extradite Mr. Safarov on the assumption that he would serve at least 25 years of a life sentence. It has set off protests in Budapest and enraged Armenia, where activists pelted the Hungarian Embassy with eggs and burned Hungarian flags.