The man who says he was the mastermind of the Sept. 11 terrorist attack seeks to justify the plot as a "natural reaction" to U.S. foreign policy in a blistering letter sent to then President Barack Obama from the Guantanamo prison.

Khalid Shaikh Mohammad, one of five Guantanamo prisoners facing trial by military commission for their alleged roles in the hijacking plot, also writes in the letter released Wednesday that it does not matter to him if he receives a life sentence or the death penalty from the tribunal.

"If your court sentences me to life in prison, I will be very happy to be alone in my cell to worship Allah the rest of my life and repent to him all my sins and misdeeds," Mohammad wrote. "And if your court sentences me to death, I will be even happier to meet Allah and the prophets and see my best friends whom you killed unjustly all around the world and to see Sheikh Usama Bin Laden."

Mohammad sought to send the letter in 2015 but was prevented by prison authorities and later by the military judge presiding over his case at the request of prosecutors, who labeled it "propaganda." After litigating the issue, the tribunal allowed the letter to go through last month just as Obama was leaving the presidency.

The letter also condemns Obama, saying the former president's hands are "still wet with the blood of our brothers and sisters," a reference to the deaths of Palestinian civilians in Gaza at the hands of Israeli forces as well as those killed by U.S. drone strikes in Yemen and elsewhere.

"The two blessed attacks in Washington and New York adhered to all universal laws and were a natural reaction to your destructive policies towards the Islamic world," Mohammad wrote.

The contents of the letter were first published by The Miami Herald. A copy was provided to The Associated Press by lawyers for the prisoner. They expressed doubt Obama saw it since it reached the White House only days before the end of his administration.

Marine Corps Maj. Derek Poteet, a military lawyer appointed to represent Mohammad, said his client started the letter in 2014, prompted by civilian deaths in Gaza and said it echoes arguments he has made throughout his time in confinement.

"It appears to be a continuation of a consistent theme that he believes Americans do not count the casualties experienced by others around the world, perhaps especially Muslims, as being valuable," Poteet said.

Mohammad and his co-defendants face charges that include hijacking, terrorism and nearly 3,000 counts of murder in violation of the laws of war in a case that remains in the pretrial stage.

In a closed 2007 appearance before a panel of military officers, he said he planned the Sept. 11 attacks "from A to Z" and had been involved in many other plots. He said he personally beheaded Wall Street Journal reporter Daniel Pearl with his "blessed right hand," according to a transcript.

At his first public court hearing in 2008, he chanted verses of the Quran and said he would welcome becoming a martyr for his Sept. 11 role. The following year he released a written statement calling the attacks a "noble victory."

The chief prosecutor did not immediately respond to a request for comment on Mohammad's letter, but in a court filing the prosecution said Mohammad should not be allowed to "to disseminate propaganda wholly unrelated to this commission proceeding."