MAJID KHAN, a 32-year-old former Baltimore resident, admits that he volunteered to work for al-Qaeda and Khalid Sheik Mohammed, the self-proclaimed mastermind of the Sept. 11, 2001, terrorist attacks. He acknowledges funneling $50,000 to operatives who used the money for a deadly bomb attack in Indonesia. And he told a military court last week that he had plotted with Mr. Mohammed to blow up gas stations in the United States.

Military prosecutors at the U.S. Naval Base at Guantanamo Bay, Cuba, where Mr. Khan has been imprisoned, now have secured a fair but appropriately tough plea deal that should smooth the way for a military trial of the alleged 9/11 perpetrators.

Mr. Khan, who has been in U.S. custody since 2003, pleaded guilty to five counts of violating laws of war, including murder and attempted murder; if convicted at trial, he could have faced life behind bars. The plea calls for Mr. Khan to remain incarcerated for no more than an additional 19 years as of the date of the plea bargain, but only if he testifies truthfully against other high-value detainees, including, most likely, Mr. Mohammed. He could face 25 more years behind bars if he does not hold up his end of the bargain.

In securing the guilty plea, prosecutors drove an appropriately tough bargain. Mr. Khan cannot seek credit for the years he has already served at Guantanamo. He cannot sue the government or challenge his conviction because of alleged torture. As Mr. Khan acknowledged in a military hearing last week, he can be detained as an enemy combatant after he completes his criminal sentence if the government decrees it is warranted, though the government (also appropriately) recognizes Mr. Khan’s right to challenge such an indefinite detention in a federal court.

Any plea bargain, with its potential for a defendant’s release, brings risks. But prosecutors, led by Brig. Gen. Mark Martins, used the possibility of a life sentence as leverage to gain Mr. Khan’s cooperation against allegedly bigger culprits even while insisting on a sentence that reflects the seriousness of Mr. Khan’s crimes.

For too long, military proceedings at Guantanamo were tragically flawed, unfair both to defendants and to the victims of terrorism. Congress addressed these shortcomings in 2009 by vastly improving military commissions, in large part by shoring up legal protections for defendants. This legitimacy rightly helped to ward off legal challenges to the system and paved the way for last week’s progress.