RIYADH, Saudi Arabia — President Obama and King Salman of Saudi Arabia spent more than two hours in a closed-door meeting that American officials said was cordial but underscored deep differences with the kingdom over Iran, human rights and the best way to fight terror.

The two leaders met in Riyadh on Wednesday against the backdrop of a public debate in the United States Congress about a bill that would allow the Saudi government to be held legally responsible for the Sept. 11, 2001, attacks if it is established that any officials played a role — a charge Saudi officials have long denied.

Administration officials said the issue of the Sept. 11 attacks did not come up during the meeting with the king at Erga Palace, an opulent compound lined with palm trees and well-manicured royal grounds.

American officials said Mr. Obama pressed King Salman to be more open to engaging in diplomacy with Iran and to find alternatives to direct confrontation with Iranian leaders and other rivals in the region. They described the king as highly skeptical of efforts to work with Iran, the Saudis’ chief rival in the region and the backer of rebels in Yemen that the Saudis are fighting.