Donald Trump has said the US missile strike on a Syrian air base was launched because preventing the use of chemical weapons is “in the vital national security interest”.

But he was publicly opposed to military intervention when Barack Obama made the case for military action against the Syrian government four years ago.

“Again, to our very foolish leader, do not attack Syria – if you do many very bad things will happen and from that fight the US gets nothing!” wrote Mr Trump in capital letters on 5 September 2013.

Two days later, he added: “President Obama, do not attack Syria. There is no upside and tremendous downside. Save your ‘powder’ for another (and more important) day!”

Mr Obama said a chemical attack carried out in August that year was “a crime against humanity, and a violation of the laws of war”, but decided against intervention after he consulted Congress, who did not support the air strikes.

This means the surprise barrage of 59 cruise missiles, ordered by Mr Trump, is the first direct US attack on the Syrian government.

The President was reacting to the attack on Tuesday that killed at least 72 people, including 20 children, which he said was launched by Syrian president Bashar al-Assad.

Speaking from Florida, Mr Trump announced his strike in an emotional message to the public in which he evoked images of children dying.

“Using a deadly nerve agent, Assad choked out the lives of helpless men, women and children. It was a slow and brutal death for so many,” he said. “Even beautiful babies were cruelly murdered in this very barbaric attack.

“Tonight, I ordered a targeted military strike on the airfield in Syria from where the chemical attack was launched.”

In his tweets at the time of Mr Obama’s speech, Mr Trump said: “What will we get for bombing Syria besides more debt and a possible long-term conflict? Obama needs Congressional approval.”

However he did not seek a vote from Congress before launching his own military strike, which Secretary of State Rex Tillerson said did not represent a change in US policy on Syria.

“Assad is a brutal dictator who must be held accountable for his actions,” Virginia Democratic Sen. Tim Kaine, democratic senator for Virginia, said in a statement, reported CNN.

“But President Trump has launched a military strike against Syria without a vote of Congress. The Constitution says war must be declared by Congress.”

While Mr Trump’s previous tweets advised Mr Obama against military intervention in Syria, he said if any action did take place, it should be “by surprise”.

“Why do we keep broadcasting when we are going to attack Syria. Why can’t we just be quiet and, if we attack at all, catch them by surprise?” he wrote on 29 August 2013.

He also wrote: “I would not go into Syria, but if I did it would be by surprise and not blurted all over the media like fools.”

“If we are going to continue to be stupid and go into Syria (watch Russia), as they say in the movies, shoot first and talk later!” he added the same day.