Media playback is unsupported on your device Media caption Wing Commander Abhinandan Varthaman was handed over to Indian officials near a border crossing with Pakistan

Pakistan has freed an Indian fighter pilot captured after his plane was shot down in Pakistan-administered Kashmir.

Wing Commander Abhinandan Varthaman was handed over to Indian officials on Friday at the only legal border crossing with Pakistan.

Minutes earlier, the pilot said on Pakistani TV that he was "very impressed" by the Pakistan army.

On Thursday Pakistan's Prime Minister Imran Khan said the pilot's release was a "peace gesture" to India.

India and Pakistan - both nuclear powers - claim all of Kashmir, but each controls only parts of it.

The pilot is being hailed as a hero in India, with fireworks being set off in the capital Delhi.

Praising the pilot, Indian Prime Minister Narendra Modi said the nation was "proud of your exemplary courage".

What does the pilot say?

In what appeared to be an edited statement aired on Pakistan TV, the wing commander described how he was shot down and rescued from an "agitated" crowd by Pakistani soldiers.

"The Pakistan army looked after me really well, they are very professional," the pilot said while in uniform, adding that he saw potential for peace.

Image copyright AFP/Getty Image caption The video statement was released by Pakistan's military minutes before the pilot walked across the border

On Friday evening, the pilot went through medical check-ups and was debriefed by India's military in the capital Delhi.

He will be reunited with his family this weekend, officials said.

Back from the brink

Rajini Vaidyanathan, BBC South Asia correspondent in Amritsar

From the early hours of the morning crowds began to build at the Indian side of the Wagah border, the main crossing between India and Pakistan.

Some were waving Indian flags, others had them painted on their cheeks.

Today's events appear to have walked the nuclear neighbours back from the brink, but the underlying issues remain.

India wants a firm commitment from Pakistan when it comes to flushing out militants on its soil - today the Pakistani foreign minister told the BBC he would act on this.

But Indian officials could be sceptical - having raised these concerns before.

What led to this moment?

Tensions between the two countries have escalated sharply in the past few weeks.

On Tuesday, India carried out air strikes on what it said was a militant camp in Pakistan in retaliation for a suicide bombing that killed at least 40 Indian troops in Indian-administered Kashmir on 14 February.

A Pakistan-based group said it carried out the attack - the deadliest to take place during a three-decade insurgency against Indian rule in Kashmir.

Pakistan - which denies any involvement in the 14 February attack - said it had no choice but to retaliate to the Indian raids with air strikes on Wednesday. That led to a dogfight and the Indian fighter jet being shot down in Pakistan-administered Kashmir.

Media playback is unsupported on your device Media caption Life on both sides of the Kashmir conflict

What caused the tensions?

India and Pakistan have fought three wars since independence from Britain and partition in 1947. All but one were over Kashmir.

Tens of thousands of troops remain positioned on either side of the border in the disputed region.

The aerial attacks across the Line of Control (LoC) dividing Indian and Pakistani territory are the first since a war in 1971.

At the height of the tension Pakistan closed its airspace, disrupting major air routes. Partial operations have now resumed at four main airports, with the full resumption of flights expected next week.

"As a peace gesture we are releasing the Indian pilot tomorrow," Mr Khan told Pakistani lawmakers in the National Assembly on Thursday.

On Wednesday he pushed for talks with Delhi to prevent the risk of a "miscalculation" between the nuclear-armed neighbours.

Media playback is unsupported on your device Media caption Footage appears to show wreckage from a downed Indian jet

What happened to the pilot?

Pakistan's military spokesman said that Pakistan fighter jets had carried out "strikes" - exactly what they did remains unclear - in Indian-administered Kashmir on Wednesday.

Two Indian air force jets then responded, crossing the de facto border that divides Kashmir. "Our jets were ready and we shot both of them down," Maj Gen Asif Ghafoor said.

He said that one Indian pilot was in the custody of the Pakistani army.

Image copyright Hindustan Times/Getty Image caption Jubilant Indians celebrated the pilot's release in New Delhi

Images then circulated of Wing Commander Abhinandan Varthaman's capture, which were condemned for what appeared to be a physical attack at the hands of residents in Pakistan-controlled Kashmir, but also praised because of the actions of the Pakistani soldiers who intervened to create a barrier.

Pakistan's information ministry published - but subsequently deleted - a video showing the blindfolded pilot, who could be heard requesting water, just after he had been captured.

In later footage, he could be seen sipping tea from a cup without a blindfold.

India's foreign ministry later issued a statement demanding the release of its fighter pilot and condemning the images, describing them as a "vulgar display of an injured personnel".

The pilot's family have not yet commented on the events, but footage shared on social media shows passengers on a Chennai to Delhi flight cheering his parents.