NEW DELHI — When an Indian fighter pilot who had been captured by Pakistan was released on Friday, it capped a humiliating episode for India and a surreal week for him.

First the pilot, Wing Cmdr. Abhinandan Varthaman, was soaring through the sky in a MiG-21 on Wednesday. Then he was shot down by Pakistani forces.

After parachuting into enemy territory and being surrounded by a mob, he tried to eat some of the documents he was carrying, according to Indian news media reports. He was then badly beaten before being rescued by Pakistani troops.

But that wasn’t the end of it. Over the next few days, videos of him being interrogated in Pakistani custody spread on social media around the world.