Mr. Trump did not elaborate on the conversation. But he appeared to be referring to a phone call he had days earlier with King Salman.

In his remarks here in Bahrain, home to the Navy’s Fifth Fleet, Mr. Mattis sought to tamp down increasing concerns that if Washington reduces its security role in the Middle East, Russia would move quickly to fill the vacuum.

The United States has not had an aircraft carrier in the Persian Gulf since March, and the Pentagon is pulling Patriot missile-defense systems out of Jordan, Kuwait and Bahrain as part of a strategic realignment of firepower away from the Middle East and toward Russia and China.

“Russia’s presence in the region cannot replace the longstanding, enduring and transparent U.S. commitment to the Middle East,” Mr. Mattis said.

Indeed, the bulk of Mr. Mattis’s speech focused on what he said was Iran’s destabilizing actions in Iraq, Syria, Yemen and Lebanon — “spreading mischief and murder across the region,” as the secretary put it.

The speech was likely to be well received in some quarters.

“It was what Saudi Arabia and its allies wanted, and are delighted to hear: a reaffirmation of America’s commitment to the region, to its partners and of course to a blanket hostility toward Iran and all Iran does,” said Robert Malley, the president of the International Crisis Group and a former White House coordinator for the Middle East, North Africa and the Gulf during the Obama administration.

When Mr. Mattis served as the four-star general and leader of the military’s Central Command during the Obama administration, he blamed Iran for deadly attacks by Shiite militias in Iraq. He advocated confronting Iran, a position that put him at odds with President Barack Obama, who was trying to engage Iran diplomatically.