It’s early March in Marrakech, and a gleaming conurbation of hotels run in the kind of rare equilibrium of slick organisation and genuine friendliness that Tyler Brûlé might dream about.

Inside, the people who run the internet’s naming and numbering systems have been meeting with some of the governments who would rather be doing the job themselves. Eventually they cut a deal, and then negotiators from countries mostly in the northern hemisphere staggered blinking into the sunlight and splayed like lizards around the azure swimming pools, almost too tired to drink. Almost.

What they have agreed is a plan for Icann, the Internet Corporation for Assigned Names and Numbers, to end direct US government oversight control of administering the internet and commit permanently to a slightly mysterious model of global “multi-stakeholderism”.

Like any settlement of a long-running conflict, the trick is to spread the unhappiness evenly and not celebrate too much, lest anyone think they’ve lost more than they’d reckoned. Though the French government was still seething over a spat about “dot champagne”, it rallied the naysayers the weekend before the official meeting started. Yet the real worry was the United States.

Larry Strickling, assistant secretary at the US Department of Commerce, is a man who defines jovial calm, but I pity any rug salesman who tries to get one over on him at the medina. He has steadily navigated the US government towards fulfilling its original commitment to Icann’s independence almost 20 years ago, but he has a tough crowd back home. To avoid spooking Republican congressmen or presidential candidates, Icann won’t big up last week’s historic achievement. Make no mistake, though, Thursday 10 March 2016 was a bright shining day on the internet. Internet Independence Day, no less.

But why did we even need a carefully brokered deal to make managing the internet the world’s business, and not America’s prerogative?

When Icann was founded in 1998, the plan was to keep its anchoring contract with the US National Telecommunications and Information Administration (NTIA) for a year or two, and for Icann to become independent in 2000. But in the meantime, the internet became just too important for the US to let go of the reins.

Shielded by the US, Icann resisted attempts by the United Nations’ International Telecommunication Union to take over its job. Iana (the Internet Assigned Names Authority, the part of Icann that deals with country codes, internet numbers and protocols) went on being part of Icann, even as other countries felt sure the US must be abusing its power behind the scenes. And Icann’s “multi-stakeholder model” evolved; a hodge-podge of different interests, meeting by conference call, email list and in different cities around the world to manage the domain name system.

But as the millions of dollars of business transacted over the internet became trillions, and the first, second and then third billion people came online, it started to look a bit odd that one government had de jure control of a chunk of the internet. And that this oversight was done via a procurement contract.

Even as Icann staff travelled the world saying “we’re just a technical coordination organisation”, having a California not-for-profit organisation run part of the global infrastructure no longer passed the sniff test.

Under pressure from the EU and others, Icann and the US government took small steps, spelling out their relationship in a deceptively simple document, the Affirmation of Commitments, in 2009. Icann and the US would probably have muddled along together for another decade, with the occasional hand-wave towards global accountability.

And then Snowden happened.

In September 2013, just months after the first Snowden revelations confirmed long-suspected global internet surveillance by the US, the internet’s elders rebelled. Technical organisations around the world issued the “Montevideo Statement”. No one was more surprised than themselves when the sleeping giants of technical organisations woke up and growled that the “recent revelations of pervasive monitoring and surveillance” had undermined the trust of internet users around the world. It was time, they said, to hurry up and “globalise the Iana”.

In a prescient flash of political brilliance, Icann’s CEO, Fadi Chehade, made a pact with Brazil’s President Dilma Rousseff. Still smarting over the NSA tapping her smartphone, Rousseff announced a global meeting to decide the future of the internet. But just a few weeks before the meeting in early 2014, the US leapt in to grab back the steering wheel from Brazil, announcing it was finally ready to let go of Icann/Iana. There were just a few conditions.

The new oversight model had to be multi-stakeholder. It had to be developed by the world’s internet community, whoever that is. It could not be run by governments. And only the US government could decide if the new model passed the test.

It has taken almost two years, one contract extension, 32,000 emails and 600 meetings to put the plan for the future of the internet together. It comes in two parts; one to transition Iana out of US control (Iana transition proposal) but keep it part of Icann, and the other for a much-needed beefing up of Icann’s anaemic accountability mechanisms.

Last week’s nail-biting days in windowless rooms were dominated by how to keep Icann honest when that’s no longer the NTIA’s job, and how to give governments a role but not a veto overall. The plan has plenty of ugly compromises and, yes, everyone is about equally unhappy with it.

What happens next? After some more intensive lawyering, the plan goes to the US NTIA in April. The NTIA must get it approved before Icann’s contract expires in September, and well before the Obama administration finishes. So far, the signals are good. But in a presidential election year, anything could happen.

Will the internet work any differently? All being well: no. Domain names will go on resolving. Internet protocol numbers will be distributed (IPv6 ones, anyway) And internet protocol parameters will … do whatever it is they do.

And can a multi-stakeholder system of lobbyists, geeks and idealists (but mostly lobbyists) really run a complex technical ecosystem the world relies on? Icann’s board says that just having come up with the plan is “a true demonstration of the strength and triumph of the multi-stakeholder model”. Time will tell.

• Maria Farrell worked for Icann from 2005 to 2010 and represented European civil society organisations on its Generic Names Supporting Organisation from 2012 to 2014