ROME — Diplomats from 17 nations on Sunday urged leaders of some of Libya’s rival political factions to form a unity government that could reverse the nation’s descent into anarchy and prevent the Islamic State and other extremist groups from seizing more territory.

“We refuse to stand by and watch a vacuum filled by terrorists,” Secretary of State John Kerry said at a news conference after the meeting in Rome. “The leaders who are here, we are convinced, speak for most Libyans. Those leaders have endorsed what is the only legitimate basis for moving ahead.”

The 15 Libyan leaders who attended the conference here had already agreed to meet in Morocco on Wednesday to discuss the formation of a government. Other Libyan tribal and regional cohorts have refused to take part.

The diplomats also pledged to provide Libyans with much-needed humanitarian assistance.

“We call on all parties to accept an immediate, comprehensive cease-fire in all parts of Libya,” read a statement from the diplomats, who met under the auspices of the United Nations, the European Union, the African Union and the Arab League.