Secretary of State John F. Kerry and Libyan Prime Minister-designate Fayez al-Sarraj at talks in Vienna on Monday. (Leonhard Foeger/AFP/Getty Images)

Diplomats from 25 countries and international organizations, including the United States, said Monday that they are considering arming and training the new unity government in Libya so it can fight the spread of terrorist groups in the country and counter the smuggling of migrants to Europe.

In a joint communique after a lengthy meeting on ways to rein in chaos in Libya, the diplomats said they would support Libya’s request to be exempted from a U.N. embargo that was put in place five years ago to keep arms out of the hands of Islamist militants and rival militias locked in a power struggle.

Other parts of the embargo would be reinforced, the communique said, so that arms go only to the forces being established by the “government of national accord” that returned to Libya six weeks ago when Prime Minister Fayez Serraj arrived on a boat with his allies.

The statement was signed by the United States and 20 other nations, including four other permanent members of the U.N. Security Council, and by four organizations: the European Union, the United Nations, the Arab League and the African Union. It said the signatories are “ready to respond to the Libyan government’s requests for training and equipping” security forces­ that are part of the new government.

Secretary of State John F. Kerry said it was “imperative that the international community should support the Serraj government, which is the only legitimate one in Libya and which must now start to work.”

Kerry told reporters at a news conference that the signatories are waiting for an official request so it can be discussed and voted on at the United Nations. He said the arms embargo specifically grants exceptions if they are requested by an accepted government that wants weapons to secure the country and combat the Islamic State. Kerry said they also wanted some parts of the embargo strengthened to deter arms transfers to groups not controlled by the recognized government.

“It’s a delicate balance,” he added. “We are, all of us here today, supportive of the fact that if you have a legitimate government, and the legitimate government is struggling against terrorism, that legitimate government should not be made the prisoner, or should not be victimized by virtue of the U.N. action that has been taken and has always awaited a legitimate government.”

Italian Foreign Minister Paolo Gentiloni told reporters that the key to fighting terrorism and waves of migration is to stabilize Libya.

“With stabilization, we can fight terrorism,” he said. “We can assure development to a country with rich potentialities but with a strong humanitarian crisis now. We can tackle the migration issue. We can develop the resources of Libya. Without stabilization, we risk tensions, divisions and intra-Libyan fights.”

Serraj called the situation in Libya “extremely bad” and warned that if no action is taken, other nations would not be spared further attacks by the “forces of terrorism that are lying in wait in Libya.”

The dark warning came near the beginning of a week that Kerry will spend in the Middle East and Europe for discussions about crises in Syria, Libya and Central Asia. The United States and other Western countries have grown alarmed as the conflicts in Libya and Syria in particular have worsened. They are seeking political solutions as a first step so that more military force can be trained on the Islamic State and other extremist groups that have expanded their presence amid the chaos.

On Sunday, Kerry was in Jiddah, Saudi Arabia, to discuss ways to firm up a shaky truce in Syria, particularly around the northern city of Aleppo. The 17 nations in a group urging peace talks aimed at establishing some kind of transitional government in Syria plan to meet Tuesday in Vienna, where State Department officials say much of the focus is expected to be on providing greater access for humanitarian deliveries of food and medicine.

Monday was primarily devoted to concerns about Libya in a meeting co-hosted by Kerry and Gentiloni. Italy’s history as a colonial power in Libya and its proximity to the country have led Rome to consider sending troops if it were asked. Italy, the United States, Britain and France have all inserted small groups of Special Operations forces­ into the country to counter the spread of the Islamic State.

Although the Serraj government has exerted control over a number of significant ministries and institutions, including the central bank, it still does not have the backing of a majority in the national parliament. A rival government and military are operating in the eastern part of the country, and the two administrations are beset by infighting over the country’s cash reserves and its oil industry.

The West is desperately seeking ways to provide more support to the government of national accord in Tripoli so that it can direct its efforts toward the Islamic State extremists, who have doubled in number over the past year and are now an estimated 6,000 strong. Western governments also want Libyan authorities to better patrol the coastline and stem the flow of refugees toward Italy.

U.S. Special Operations troops have been stationed at two outposts in eastern and western Libya since late 2015 and are tasked with lining up local partners before a possible offensive against the Islamic State, U.S. officials said last week, speaking on the condition of anonymity to discuss a sensitive mission.

A U.S. airstrike in February on a suspected Islamic State camp killed at least 40 people, including a senior operative, Noureddine Chouchane, who was linked to attacks against Western tourists in neighboring Tunisia.

Libya has been in a downward spiral of violence since strongman Moammar Gaddafi was ousted in 2011. The Libyan conflict is feared to be bleeding into Tunisia, a country considered the only successful young democracy to emerge from the 2011 Arab Spring revolts.

The joint communique ended on an optimistic note. The countries represented all said they were willing to reopen their diplomatic missions in Libya once the security situation improves.

Later Monday, Kerry met with the presidents of Armenia and Azerbaijan, in an attempt to defuse escalating violence over the Nagorno-Karabakh region, the scene of separatist warfare. He was joined by Russian Foreign Minister Sergei Lavrov and French Foreign Minister Jean-Marc Ayrault.

The small breakaway region, an enclave of mostly ethnic Armenians, declared independence from Azerbaijan in 1992 but has not been recognized by any country. A 1994 cease-fire has often been breached, and tensions escalated over four days in early April, leaving 350 people dead.

According to a statement issued after the meeting, Armenian President Serge Sarkisian and Azerbaijani President Ilham Aliyev “reiterated their commitment to the cease-fire and the peaceful settlement of the conflict.”

Brian Murphy in Washington contributed to this report.