America has no one to blame but itself for the terrorist attacks of September 11, wrote the supposed 9/11 mastermind in a letter given to President Barack Obama days before he left office.

"Your hands are still wet with the blood of our brothers and sisters and children who were killed in Gaza," wrote Khalid Sheik Mohammed in the opening paragraphs of the 18-page letter dated 8 January 2015.

Written inside Guantanamo Bay prison, it calls President Obama "the head of the snake." It was sent to him on 17 January 2017 after a military judge ordered it to be delivered. The Miami Herald has now obtained a copy of the letter.

During a military tribunal held at Guantanamo Bay prison in 2007, Mohammed claimed he was "responsible for the 9/11 operation, from A to Z."

The letter's opening paragraphs focus on the plight of Palestinians and land occupied by Israel, but it quickly shifts to call the president a liar. "In the democratic system, the first station to test his reprehensible talent (lying and deceiving) is the election campaign," Mohammed wrote. He goes on to list five instances where presidents lied, including during Watergate and the Iran-Contra scandal, and uses these to justify terrorist attacks.

Mohammed is connected to virtually every al-Qaeda attack between 1993 and 2003, according to US military and intelligence officials. He was arrested in Pakistan, his home country, in 2003 after he was placed on the FBI's list of the Most Wanted Terrorists and linked to the 9/11 terror attacks on the World Trade Center and Pentagon that killed 2,996 people and wounded 6,000.

Mohammed was then held at a secret ocerseas CIA prison before being transferred to Guantanamo Bay in 2006. The Senate Intelligence Committee report on the CIA's torture programme, released in 2014, says that he was waterboarded 183 times. The practice is now outlawed in the US as torture.

In the letter Mohammed rails against the "businessmen, lobbyists, and pressure groups that own the major media." He graduated from North Carolina A&T University, Mechanical Engineering, in 1986 and bases his justification for terrorist attacks largely on US foreign policy.

"The war crimes perpetrated in Palestine since 1948, and those taking place in Gaza today," he wrote to Obama, "are the clearest indication of why 9/11 happened, and why it may happen again in the future."