Pakistan says it has shot down two Indian military jets and captured a pilot in a major escalation between the nuclear powers over Kashmir.

India said it had lost one MiG-21 fighter and demanded the immediate and safe return of its pilot.

Pakistani PM Imran Khan said the two sides could not afford a miscalculation with the weapons they had.

India and Pakistan - both nuclear-armed states - claim all of Kashmir, but control only parts of it.

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

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

They follow a militant attack in Kashmir which killed at least 40 Indian troops - the deadliest to take place during a three-decade insurgency against Indian rule in Kashmir. A Pakistan-based group said it carried out the attack.

The BBC's Soutik Biswas, in Delhi, says the challenge for India and Pakistan now is to contain the latest escalation before things get completely out of control.

What do we know about the situation?

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. Officials had previously said two pilots had been captured and one had been taken to hospital.

No explanation has been given as to why the numbers have changed.

Maj Gen Ghafoor said the captured Indian pilot, Wing Commander Abhinandan, was being "treated as per norms of military ethics".

Earlier Pakistan's information ministry published but subsequently deleted a video showing the pilot - blindfolded and with blood on his face - identifying himself to soldiers.

Another video circulating on social media appeared to show the pilot being beaten by residents in Pakistan-controlled Kashmir before the arrival of Pakistani soldiers.

Pakistan's information ministry also tweeted what it said was footage of one of the downed Indian jets.

In India, Ministry of External Affairs spokesman Raveesh Kumar acknowledged the loss of a jet and its pilot.

He also said that an Indian plane had shot down a Pakistani fighter jet, and Indian ground forces observed it falling on the Pakistani side of the LoC. Pakistan denied any of its jets had been hit.

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

How are India and Pakistan reacting?

In a televised address, Prime Minister Khan offered India talks over terrorism and warned against further escalation.

"If we let it happen, it will remain neither in my nor Narendra Modi's control," he said.

"Our action is just to let them know that just like they intruded into our territory, we are also capable of going into their territory," he added.

Mr Modi has yet to comment but was meeting top security and intelligence officials to discuss the situation, reports in India said.

Indian Foreign Minister Sushma Swaraj said her country would act "with responsibility and restraint".

"India does not wish to see further escalation of the situation," she said, speaking from a meeting with Russian and Chinese foreign ministers in China.

What about the earlier air strikes?

Pakistan's assertion that it had shot down two Indian aircraft came shortly after Islamabad said its warplanes had struck targets in Indian territory.

Indian authorities said the Pakistani jets had been forced to withdraw.

Pakistan's military spokesman Maj Gen Ghafoor said jets had "engaged" six targets in Indian territory but then carried out air strikes on "open ground".

"We don't want to go on the path of war," he said.

India said Tuesday's air strikes on Balakot in north-western Pakistan killed a large number of militants, but Pakistan said there had been no casualties.

The US, EU and China have all called for restraint.

The challenge for India and Pakistan now is to contain the escalation before things get completely out of control.

It is almost unprecedented for two nuclear-armed countries to carry out air strikes into each other's territories.

"We are in uncharted waters," Husain Haqqani, the former Pakistani ambassador to the US and adviser to three Pakistani prime ministers, told me late on Tuesday.

An Indian defence analyst believes Indian security forces will now have to be prepared for a "full spectrum of conflict".

However Daniel Markey from Johns Hopkins University in the US says we are "several steps away" from nuclear escalation.

A further escalation, he believes, will happen if Pakistan's "next step were to raise the stakes by hitting Indian civilian targets".

That is highly unlikely.

Pakistan has closed its entire airspace, its civil aviation authority said. Nine airports in northern India were temporarily closed but have now reopened, reports in India say.The flight monitoring group Flight Radar says international flights have been avoiding the area.