MUMBAI, India  The sole surviving gunman of the deadly rampage in Mumbai unexpectedly confessed in court here on Monday, adding his voice, matter-of-fact even as he spoke of opening fire into crowds, to what may be the most well-documented terrorist attack anywhere.

The gunman, Ajmal Kasab, 21, was the man in an infamous surveillance photograph, looking calm with a blue T-shirt and a machine gun. The photograph was one part of an extraordinary electronic record reviewed during the trial, which the judge ruled would go on. Other tapes showed his fellow gunmen shooting up luxury hotels. Recordings of intercepted phone calls provided a spooky, real-time narration between the handlers and the gunmen, who at times needed to be prodded into action and were stunned at the opulence of one hotel.

“Everything is being recorded by the media,” one of the handlers told the gunmen at the Oberoi Hotel. “Inflict maximum damage. Keep fighting. Don’t be taken alive.”

But it did not appear to be the evidence that prompted Mr. Kasab to confess to his role in the attacks, where more than 160 people were killed in November in luxury hotels, a train station, a popular cafe and a Jewish center. He said it was because his native Pakistan, which had denied any role in the attacks, had begun cooperating more with India and identified him as a participant.