Secretary of State John F. Kerry speaks during a news conference after an international meeting on Libya in Rome on Sunday. (Tiziana Fabi/Agence France-Presse via Getty Images)

Diplomats fearful of advances by Islamist militants in the chaos of Libya endorsed a plan Sunday for a cease-fire and a national unity government, potentially paving the way for the North African country to receive support and arms from a host of foreign countries.

“We refuse to stand by and watch a vacuum filled by terrorists because all of us are unwilling to help people who want their freedom, want their independence, want their country back,” said Secretary of State John F. Kerry, who, together with Italian Foreign Minister Paolo Gentiloni, co-chaired a summit aimed at stopping Libya’s slide into anarchy.

Kerry joined 20 other diplomats from Europe, Africa and the Middle East to address mounting concern that Libya is about to become, as Italian Prime Minister Matteo Renzi recently said, “the next emergency” after Syria.

They talked with 15 officials from both of Libya’s two rival governments, all of whom were part of a tentative power-sharing agreement scheduled to be signed in Morocco on Wednesday. The Rome meeting’s goal was to reassure them that if they follow through and a majority in both parliaments sign the agreement, foreign aid would be forthcoming.

The diplomatic efforts offer the brightest hopes yet for an end to the mayhem that has overwhelmed Libya since Moammar Gaddafi was deposed and killed in 2011. Libya is now a bifurcated state, with an internationally recognized government in the eastern city of Tobruk and a separate parliament backed by Islamist militias in the capital of Tripoli.

Italy, Libya’s former colonial power, called the conference. It is particularly concerned about threats posed by the North African country only 180 miles off its coast. The proximity has made Libya a jumping-off point for tens of thousands of refugees heading to Europe.

Increasingly, Europeans worry that Libya could become a new breeding ground for fighters escaping the battlefields of Syria and Iraq. From there, they could plot attacks against Western capitals, especially those of countries conducting airstrikes against the Islamic State in parts of Syria and Iraq. According to a recent U.N. report, an estimated 2,000 to 3,000 Islamic State fighters are now in Libya. The Islamic State already controls the city of Sirte, Gaddafi’s home town, but has faced “strong resistance from armed residents,” the report said.

A new government that could counter the Islamic State advance is finally on the horizon. After more than a year of U.N. mediation efforts, a majority of lawmakers from Libya’s two rival parliaments appear to have tentatively decided to share power. If they sign the agreement in Morocco on Wednesday, a new government would be formed by early February. Some hard-liners, though, have denounced the agreement and are not expected to abide by it, and it’s unclear how widespread support is.

A senior State Department official traveling with Kerry told reporters that advances by the Islamic State — also known by its Arab acronym, Daesh — helped persuade many people within the rival governments to put aside their differences and cooperate.

“I think, as Samuel Johnson once said hundreds of years ago, the prospect of hanging concentrates minds, and the threat from Daesh certainly aided in the recognition by Libyans that they need to come together and form a single government,” said the official, speaking on the condition of anonymity under State Department rules for briefing reporters.

The official said that the new government is expected to formally ask for international help in combating Islamic State militants and that the request will be swiftly granted.

“It’s clear that Libya needs to have one government that’s capable of getting trained and equipped in order to be able to take on Daesh more effectively,” the official said. “The Libyans want to fight back. They want international help in fighting back. The political agreement allows the government to ask for help. We expect the government will ask. We expect that they will do so and that outsiders will then help with training and equipping in appropriate ways.”

Libya is rich in oil, and despite its budget being bled by the fighting and corruption, it is believed to have at least $50 billion in oil revenues left in savings. Although oil prices have fallen dramatically, the savings could be replenished once a government gets control of the oil fields that are pumping at only one-quarter or less of their capacity, the official said.