An infant boy handed in desperation to a soldier across an airport wall in the chaos of the American evacuation of Afghanistan has been found and has finally been reunited with his relatives in Kabul.

The baby, Sohail Ahmadi, was just two months old when he went missing on 19 August as thousands of people rushed to leave Afghanistan as it fell to the Taliban.

The baby was located in Kabul where a 29-year-old taxi driver named Hamid Safi had found him in the airport and took him home to raise as his own.

After more than seven weeks of negotiations and pleas, and ultimately a brief detention by Taliban police, Mr Safi finally handed the child back to his jubilant grandfather and other relatives still in Kabul.

They said they would now seek to have him reunited with his parents and siblings who were evacuated months ago to the United States.

Baby Sohail drinking milk inside the house of Hamid Safi in Kabul

During the tumultuous Afghan evacuation over the summer, Mirza Ali Ahmadi - the boy's father who had worked as a security guard at the US embassy - and his wife Suraya feared their son would get crushed in the crowd as they neared the airport gates en route to a flight to the United States.

Mr Ahmadi said in early November in his desperation that day, he handed Sohail over the airport wall to a uniformed soldier who he believed to be an American, fully expecting he would soon make it the remaining five metres to the entrance to reclaim him.

Just at that moment, Taliban forces pushed the crowd back and it would be another half an hour before Mr Ahmadi, his wife and their four other children were able to get inside. But by then the baby was nowhere to be found.

Mr Ahmadi said he searched desperately for his son inside the airport and was told by officials that he had likely been taken out of the country separately and could be reunited with them later.

The rest of the family was evacuated - eventually ending up at a military base in Texas. For months they had no idea where their son was.

Chaos at Kabul airport amid the Taliban takeover last August (file image)

The case highlights the plight of many parents separated from their children during the hasty evacuation effort and withdrawal of US forces from the country after a 20-year war.

With no US embassy in Afghanistan and international organisations overstretched, Afghan refugees have had trouble getting answers on the timing, or possibility, of complex reunifications like this one.

The US Department of Defense, the State Department and the Department of Homeland Security did not respond to requests for comment.

On the same day Mr Ahmadi and his family were separated from their baby, Mr Safi had slipped through the Kabul airport gates after giving a ride to his brother's family who were also set to evacuate.

Mr Safi said he found Sohail alone and crying on the ground. After he said he unsuccessfully tried to locate the baby's parents inside, he decided to take the infant home to his wife and children.

He has three daughters of his own and said his mother's greatest wish before she died was for him to have a son. In that moment he decided: "I am keeping this baby. If his family is found, I will give him to them. If not, I will raise him myself," he said in November.

After a Reuters story about the missing child was published last November, some of Mr Safi's neighbours - who had noticed his return from the airport months earlier with a baby - recognised the photos and posted comments about his whereabouts on a translated version of the article.

Mirza Ali Ahmadi asked his relatives still in Afghanistan to seek out Mr Safi and ask him to return Sohail to the family.

Baby Sohail Ahmadi is carried by his grandmother as they leave then house of Hamid Safi

Mr Ahmadi's father-in-law said he travelled two days and two nights to the capital bearing gifts for Mr Safi and his family, but Mr Safi refused to release Sohail, insisting he also wanted to be evacuated from Afghanistan with his family. Mr Safi's brother, who was evacuated to California, said Safi and his family have no pending applications for US entry.

The baby's family sought help from the Red Cross, which has a stated mission to help reconnect people separated by international crises, but said they received little information from the organisation.

Finally, after feeling they had run out of options, the local Taliban police were contacted by Mr Ahmadi's father in-law to report a kidnapping. Mr Safi told Reuters he denied the allegations to the police and said he was caring for the baby, not kidnapping him.

The complaint was investigated and dismissed and the local police commander said he helped arrange a settlement, which included an agreement signed with thumbprints by both sides.

The baby's family in the end agreed to compensate Mr Safi around 100,000 Afghani (€830) for expenses incurred looking after him for five months.

In the presence of the police, and amid lots of tears, the baby was finally returned to his relatives.

The baby's parents said they were overjoyed as they were able to see with their own eyes the reunion over video chat.

Now Mr Ahmadi and his wife and other children, who in early December were able to move off the military base and resettle in an apartment in Michigan, hope Sohail will soon be brought to the United States.