A joint raid by U.S. and Afghan forces on Tuesday rescued the son of a former Pakistani prime minister who was held captive for three years by Islamic militants, officials said.

Ali Haider Gilani was found during the raid near Afghanistan's eastern border with Pakistan, according to a spokesman for Afghan President Ashraf Ghani. Gilani, believed to be around 30, is the son of Pakistan's former Prime Minister Yusuf Raza Gilani whose secular anti-Taliban Pakistan People's Party's led several major offensives against Islamic militants.

In Pakistan, the Foreign Ministry said the Afghan National Security Adviser Mohammad Hanif Atmar told Pakistan's foreign affairs adviser, Sartaj Aziz, in a telephone call about the development.

Ghani's spokesman, Zafar Hashemi, told The Associated Press that Gilani was being taken to the Pakistani embassy in Kabul. The embassy said he had not yet arrived.

The raid took place on Tuesday in the Gayan district of Pakitka province, Hashemi said -- not in Ghazni province as the Pakistani Foreign Office earlier reported.

It was conducted under the authority of the U.S. anti-terrorist mission in Afghanistan, Operation Freedom's Sentinel, according to a statement by the U.S. military in Afghanistan.

"Four enemy combatants were killed as a result of the operation. No other injuries or damage was observed or reported," the statement said. It said that the counter-terror mission was "planned and launched after evidence of terrorist activity was confirmed."

A spokesman for Afghanistan's National Security Council, Tawad Ghorzang, told reporters in Kabul that the rescue took place during an ongoing operation in the area against al-Qaida and other militants.

The operation did not specifically seek Gilani, but came across him in the course of anti-terrorist operations, he said.

Gilani was in good health, Ghorzang added, and "will soon be handed through diplomatic channels to Pakistan."

U.S. Army Brig. Gen. Charles Cleveland, spokesman for U.S. forces in Afghanistan, said Gilani had been flown by helicopter to the Bagram Air Field, 45 kilometers (31 miles) from Kabul, where he was receiving medical checks. "We think he is in good health," he said.

The purpose of the operation "was to go after al-Qaida-related targets in the area, and there was an indication that there may have been a hostage being held with them," Cleveland said. "So it was a nice surprise to get that."

Gilani had been held in a compound occupied in the Gaylan district by al-Qaida operatives, he said, though the "rescue happened outside the compound."

"He (Gilani) was the sole non-combatant, he didn't fight back, so we picked him up," he said. United States forces would repatriate Gilani to Pakistan once medical checks and other procedures at Bagram were complete, he said.

The Pakistani government was expected to send a plane to Kabul to collect him, Cleveland added.

The elder Gilani, who served as prime minister from 2008 to 2012, said last year that the kidnappers demanded the release of several al-Qaida prisoners in exchange for his son. He also said that the captors had let his son talk to him by phone for eight minutes, and that he was being held somewhere in Afghanistan.

Gunmen kidnapped the younger Gilani in May 2013, several days before the general elections in his central Pakistani hometown of Multan. There was no claim of responsibility for the abduction but suspicion immediately fell on the Taliban.

However, Ghorzang's account that the U.S.-Afghan raid targeted al-Qaida and other militants and the fact that Ali Haider was found inside Afghanistan -- quite far from where he was abducted in Pakistan -- indicated he might have changed hands between militant groups.

Abdul Qadi Gilani, a brother of the younger Gilani, praised Afghan authorities and Pakistan's army chief Gen. Raheel Sharif for his brother's successful recovery. He said the army chief also called their father about the rescue. A jubilant elder Gulani was seen on Pakistani TV attending an election rally after hearing the news.

"This is a very good day for me," the father said as his other son, Abdul Qadir, told reporters in Multan that his brother will arrive from Afghanistan to Islamabad later Tuesday.

"I am very happy and I have no words to express my joy," Abdul Qadir said.

Pakistan's Prime Minister Nawaz Sharif issued a statement expressing pleasure over the rescue while the current leader of the People's Party, Bilawal Bhutto Zardari, announced on Twitter the Afghan ambassador in Islamabad first called the elder Gilani to tell him about his son.

The Pakistani Taliban have fought the state for over a decade, killing tens of thousands of people in a bid to install their own harsh Islamic system.