The self-proclaimed mastermind of the 9/11 attacks sent a letter to Barack Obama during his last days in office to tell him September 11 was a direct result of American 'oppression and tyranny'.

The 18-page letter to 'the head of the snake, Barack Obama,' was written by Khalid Sheikh Mohammed, the accused 9/11 mastermind.

He has been held at the prison at Guantanamo Bay since 2006 after being captured in Pakistan in 2003.

During an interrogation in 2007, he confessed to being behind the 9/11 attacks.

Terror mastermind Khalid Sheikh Mohammed sent a letter to Obama days before the ex-President left office calling him 'the head of the snake'

The chilling letter is dated January 8, 2015, but only reached the White House in the final days of Obama's presidency.

In it, he wrote: 'It was not we who started the war against you in 9/11; it was you and your dictators in our land.'

He said God was on the side of the hijackers that fateful day when planes were sent crashing into the Twin Towers in New York, the Pentagon and a field in Pennsylvania.

The attacks that shocked the world killed 2,996 people and injured more than 6,000 others.

He wrote: 'Allah aided us in conducting 9/11, destroying the capitalist economy, catching you with your pants down, and exposing all the hypocrisy of your long-held claim to democracy and freedom.'

Listing many grievances over America's 'brutal and savage massacres' from Vietnam to the atomic bombs dropped on Hiroshima and Nagasaki, Mohammed focused his rage on the plight of Palestinians and US support for Israel and the 'occupier Jews.'

'Your hands are still wet with the blood of our brothers and sisters and children who were killed in Gaza,' he wrote in the opening paragraph.

Defense attorney David Nevin provided a copy of the letter, which has not yet been posted on the US military's website for Guantanamo proceedings.

He told AFP that Mohammed began writing it in 2014.

The chilling letter is dated January 8, 2015, but only reached the White House in the final days of Obama's presidency

Along with the letter, Mohammed sent a 51-page manuscript entitled 'Shall I Die when the Crusaders Carry out the Death Sentence? The Truth about Death.'

It was illustrated with an image of a noose.

Mohammed, who faces a potential death sentence for allegedly masterminding the plane hijackings, said he was not afraid of dying.

'I speak about death happily!' he wrote.

Mohammed was waterboarded 183 times in March 2003 and held at a secret CIA prison site overseas.

In the letter, he explained that '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.'

He added: '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 Osama Bin Laden.'