Frustrated by a year of setbacks and violence and a looming refugee crisis in a country whose birth it midwifed last summer, the Obama administration sent its top diplomat to dispense some stern advice Friday.

Make lasting peace and an oil deal with Sudan, Secretary of State Hillary Rodham Clinton told South Sudan’s president, Salva Kiir, one day after a United Nations deadline for the countries to make progress toward resolving their bitter differences. Sanctions on both are possible if fighting continues.

“A percentage of something is better than a percentage of nothing,” Clinton said, reflecting the U.S. view that South Sudan is only hurting itself by turning off an oil flow on which both countries rely.

On Saturday, a key mediator said the countries had reached an oil deal, according to Reuters.

Backed by millions of dollars in U.S. and European aid, South Sudan is the world’s newest country and by some measures its least developed. It is locked in a deadly embrace with Sudan, its detested former overlord, that U.S. officials fear is becoming a war of attrition that the northern country is far better placed to win.

Disputes over oil and territory threaten to destroy a landmark 2005 peace deal that ended what was then Africa’s longest-running civil war. Sudan’s predominantly Christian and animist south seceded from the largely Arab north in July last year, but the arrangement left borders porous and details about oil production messy.

The two Sudans came to the brink of war in April. The fighting has contributed to the displacement of more than 200,000 people — one of the worst refugee crises in the world.

Just a day after Clinton’s visit, Thabo Mbeki, the former South African president and African Union mediator in Sudan, told reporters in Ethi­o­pia that an oil deal had finally been struck.

“It’s an (oil) agreement about all of the matters. The issues that were outstanding were charges for transportation, for processing, transit,” Mbeki said, according to Reuters. He gave no details but said Sudan and South Sudan would soon determine when to resume exports of southern oil through the north.

Clinton later issued a statement welcoming the agreement, saying it reflected “leadership and a new spirit of compromise on both sides.”

She praised the “courage” shown by South Sudan’s leaders, adding, “As I said in Juba yesterday, the interests of their people were at stake.” The Khartoum government, too, deserves credit, Clinton said. “If Sudan would now also take the steps to peace in Southern Kordofan, Blue Nile and Darfur, and if it will respect the rights of all citizens, it can likewise give its people a brighter future.”

The accord was a surprise; Sudan had previously insisted on an agreement covering border security before discussions on oil production and revenue sharing.

South Sudan shut off the oil pipelines in January in a dispute over payment. Most of the former united Sudan’s oil was produced in the landlocked south but shipped out from the north.

South Sudanese Foreign Minister Nhial Deng Nhial said in talks in Ethiopia this week that the South had made a “generous offer” of a higher oil transit fee and a $3.2 billion package to compensate for the loss of oil produced in the South.

“You have made your point,” Clinton said during a news conference Friday with Nhial. “You have brought Sudan to the negotiating table.”

Clinton announced an additional $15 million for U.N. aid to the refugees, bringing the U.S. contribution to more than $50 million.

Clinton’s brief sojourn in Juba, Sudan’s rattletrap capital, was low-key. The main road from the airport is lined with low-rise shops and billboards, a few half-finished buildings and some Chinese shipping containers. A few people waved or stared as she passed. But the visit was the diplomatic heart of a 10-day trip that crisscrosses Africa and spans U.S. interests there, from traditional aid and development to economic competition with China to counterterrorism.

In Uganda later Friday, Clinton praised the heavily Ugandan military missions fighting the al-
Shabab militants in Somalia and hunting militia chieftain Joseph Kony.

The help from Uganda’s well-trained army is key to several U.S. security goals in Africa but entails a cozy relationship with Ugandan President Yoweri Museveni, one of Africa’s veteran strongmen.

Clinton is the highest-ranking U.S. official to travel to South Sudan since its creation as what Washington hoped would be a new friend to the United States and a model for the constructive deployment of U.S. aid.

South Sudan also represented a repudiation of Sudan’s government, largely shunned by the United States after years of terrorism-related sanctions and the war crimes indictment of President Omar Hassan al-Bashir.

The project has not gone as planned.

South Sudan is running out of money and testing the patience of international backers by using oil as an economic weapon, although some U.S. officials acknowledge that expectations for the country’s first year were probably set too high.

A senior U.S. official in the region who spoke on the usual diplomatic condition of anonymity said that U.S. annoyance over Kiir’s perceived mistakes has faded, but so have some American hopes for South Sudan’s role as a security stake.

Kiir’s stiff posture and carefully chosen words upon meeting Clinton suggested that he knew that his American patrons were unhappy.

The cowboy-hatted Kiir is a former rebel commander and South Sudan’s accidental president after the death of the charismatic resistance leader John Garang. Kiir particularly angered U.S. officials over the past year when he repeatedly denied that his government is still supporting rebels marooned in Sudan since South Sudan seceded last year.

Sudan claims such interference, and U.S. officials say privately that it continues despite the South’s disarmament pledges during years of U.S.-sponsored preparation for independence.