The son of a former Pakistani prime minister who was freed from kidnappers in a dramatic military rescue in Afghanistan has been handed over to Pakistan's ambassador in Kabul.

Ali Haidar Gilani arrived at the Afghan Ministry of Defense in Kabul by helicopter on Wednesday morning where he was greeted by Pakistani Ambassador Abrar Hussain. He is expected soon to be flown home to Pakistan.

Gilani was rescued during a joint U.S. -Afghan commando raid on an al-Qaida compound near the Pakistani border on Tuesday, after three years of captivity. He spent the night at a military base, undergoing medical check-ups.

At the Kabul ministry, he thanked Afghan forces for "their sacrifice for someone from another country."

His father, Yusuf Raza Gilani served as prime minister from 2008 to 2012.