Australian Timothy Weeks and American Kevin King have been released by the Taliban as part of a stalled hostage swap deal.
Prime Minister Scott Morrison says Australian academic Tim Weeks is in good spirits after being released by the Taliban in a prisoner swap.
Mr Weeks and his American colleague Kevin King were freed overnight, three years after they were abducted in Afghanistan.
The men have been flown out of the country by US officials and are undergoing medical checks.
"Tim is in a safe place, he's out, and he's coming home," Mr Morrison told reporters on Wednesday.
"We look forward to that very, very much."
The prime minister thanked the Afghan government and the United States for helping end "three years of absolute hell" for the two men.
"The fact that Tim and Mr King will be actually coming home to their respective countries is a great relief," Mr Morrison said.
"It just goes to show that if you stick at these things and you work at it quietly, you don't seek to showboat around this stuff, that you can get good outcomes for people.
"It's not always guaranteed, there are tremendous risks, and what has been able to be achieved here for Professor Weeks I think is just tremendous and I couldn't be more thrilled."
Foreign Minister Marise Payne spoke to Mr Weeks' family overnight.
"They are needless to say extraordinarily relieved, extraordinarily pleased that they will be able to welcome home Timothy and very, very grateful to those who have worked so hard to achieve his release," she told reporters in Sydney.
Mr Weeks is from Wagga Wagga in NSW, which is also home to Deputy Prime Minister Michael McCormack.
"I know all Wagga Wagga is celebrating today the freedom and the safety of Timothy Weeks," Mr McCormack said.
"Well done to everybody who helped make that happen."
Mr Weeks, 50, and Mr King, 63, who were grabbed outside the American University in Kabul in 2016, were freed in exchange for three members of the Taliban.
The people swap saw the release of Anas Haqqani, the younger brother of Sirajuddin Haqqani, who leads the Taliban's fearsome Haqqani network.
Anas Haqqani, along with an uncle, Hajji Malik Khan, and a Haqqani lieutenant, Hafiz Rashid Khan, were released by the Afghan government on Monday and flown to Qatar, where the extremist group has a political office.
Mr Weeks and his American colleague were handed over to US forces in southern Afghanistan and flown out of the country by chopper to receive medical care.
The Weeks family has asked for privacy.
"We are grateful for the efforts of the Australian government in securing Tim's release," they said in a statement.
"We would like to thank the United States government for the significant role it played in securing Tim's freedom and acknowledge the important contribution of the government of Afghanistan.
"We thank our friends and extended family for their love and support over the past three years during this very difficult time.
"While we understand the intense public interest in Tim's release, we do not want to comment further."
With AFP and AAP...