U.S. President Donald Trump delivers a speech during Arab-Islamic-American Summit in Riyadh, Saudi Arabia May 21, 2017. [Photo/Agencies]

WASHINGTON - US President Donald Trump took sides in a deep rift in the Arab world on Tuesday, praising Middle East countries' actions against American ally Qatar over Islamist militants even though the tiny Gulf state hosts the largest US air base in the region.

Trump wrote on Twitter that his recent trip to the Middle East was "already paying off" and cast an anti-Islamist speech he made in Saudi Arabia as the inspiration for a decision by Arab powers to sever ties with Qatar in protest at what they say is the Gulf nation's support for terrorism.

"So good to see the Saudi Arabia visit with the King and 50 countries already paying off. They said they would take a hard line on funding extremism, and all reference was pointing to Qatar. Perhaps this will be the beginning of the end to the horror of terrorism!" Trump wrote on Twitter.

Qatar vehemently denies the accusations.

Trump later spoke by phone with Saudi King Salman and stressed the need for Gulf unity, a senior White House official said.

"His (Trump's) message was that we need unity in the region to fight extremist ideology and terrorist financing. It's important that the Gulf be united for peace and security in the region," the senior official told Reuters.

US officials were blindsided by Saudi Arabia's decision to sever diplomatic ties with Qatar in a coordinated move with Egypt, Bahrain and the United Arab Emirates (UAE), current and former officials in Washington told Reuters. The United States was not informed of the decision until just before it was announced, the State Department said.

Even as Trump applauded the Arab countries' move, the Pentagon on Tuesday renewed praise of Qatar for hosting US forces and its "enduring commitment to regional security."

Some 8,000 US military personnel are stationed at al Udeid in Qatar, the largest US air base in the Middle East and a staging ground for US-led strikes on the Islamic State militant group that has seized parts of Syria and Iraq.