Frontier Crimes Regulation Commissioner Sahibzada Mohammad Anees ruled that a judge in the tribal belt had exceeded his authority when he handed down the sentence last year and ordered a fresh trial.
Anees also handed over Afridi's case to the political agent of Khyber Agency. He said Afridi could be released only on the orders of the political agent.
Afridi, in his forties, was sentenced to 33 years in jail on May 24, 2012 on a charge of aiding the banned Lashkar-e-Islam militant group. The verdict was issued by the assistant political agent, who has judicial powers.
The Al Qaeda chief was killed in a unilateral US military raid in the garrison town in May 2011, sending bilateral relations into a tailspin and embarrassing Pakistan's powerful military.
More From This Section
A tribal court in the semi-autonomous Khyber Agency had sentenced Afridi, who is currently being held at the central prison in Peshawar. Legal experts and rights activists had challenged the verdict.
The US has been pressuring Pakistan to release Afridi and the matter is said to have been raised during Secretary of State John Kerry's recent visit to Islamabad.