CHICAGO — David C. Headley, an American who confessed to helping plan the deadly 2008 terrorist attacks in Mumbai, India, was sentenced here on Thursday to 35 years in prison, the maximum sought by federal prosecutors.

Balancing what was described in court as a “very heinous crime” and “very significant cooperation,” the ruling came after lawyers for the government and the defense urged Judge Harry D. Leinenweber of Federal District Court to downgrade Mr. Headley’s punishment from life in prison. They said he had cooperated with the authorities and provided useful information about Lashkar-e-Taiba, the Pakistan-based militant group with which he had worked.

“No matter how good our intelligence is, no matter how technologically advanced our investigative techniques are, we need witnesses,” Gary S. Shapiro, the acting United States attorney for the Northern District of Illinois, said after the decision. “And the only way you get witnesses in this world is by threatening to prosecute them and then offering them some real incentive to provide you with that information.”

According to court documents, Mr. Headley, 52, attended Lashkar-e-Taiba training camps in Pakistan between 2002 and 2005. He later admitted to scouting targets in Mumbai for the group before the raids in November 2008, in which 163 people and 9 gunmen died. Six of the victims were American.