A nightmare scenario of Ebola raging unchecked among millions of slum-dwellers in Africa's largest city has given way to a rare example of a victory over the virus.
Amid the gloom surrounding the escalating crisis in West Africa, developments in Lagos show how the right techniques at the right speed can bring about a welcome result.
With a population of more than 170 million, Nigeria is Africa's most populous nation and there were fears that Ebola would take hold when a Liberian-American arrived with the disease in July.
Instead, along with much smaller Senegal, Nigeria is now on the brink of being clear of the virus for a 42-day period at which point the World Health Organization (WHO) can declare it Ebola-free.
The outcome could so easily have been far uglier, and the fact that the news is happier is due to an astonishing story of medical detective work.
The starting-point was the arrival of Patrick Sawyer at Lagos airport where he collapsed and was suspected of suffering from malaria.
Taken to a private clinic, tests were carried out and during the wait for the results several staff became infected.
By the time confirmation of Ebola came through, the infections had spread to 11 of the staff - four of whom later died. This was the point where things could have gone catastrophically wrong.
An official response did not get off to a fast start but by good fortune a team of experts working to tackle polio was in place and ready to be redirected.
What followed was a text-book case of one of the guiding principles of disease control: identifying and tracking down everyone who might possibly have been in contact with the patient.
It began with the medical staff and their families and then extended to take in increasingly large numbers.
An initial contact list of 281 people soon increased to a staggering 894 - each of them visited and checked repeatedly for signs of infection.
But the sleuthing did not end there. Specialists then calculated how many people were living within a particular radius of the 894 people who were being monitored. This depended on the density of the housing in each particular area.
The result was that officials and volunteers embarked on rounds of visits that would take them to an extraordinary 26,000 households.
A key policy throughout this arduous process was to involve the communities and to encourage people to be as honest as possible about their movements and contacts. It obviously worked.
In all, there have been 19 confirmed cases of infection in Nigeria and eight deaths, including Patrick Sawyer - figures that are tragic for the families involved but infinitely smaller than they might have been.
In an ideal world, the same approach of careful record-keeping and diligent footwork would now be applied to the battered countries of Guinea, Liberia and Sierra Leone - but that is not very likely.
Nigeria, though notorious for its corruption and inefficiency, evidently has a bureaucracy that functions effectively enough for the strategy to counter Ebola to succeed - unlike the three hardest-hit countries which were suffering from extreme poverty and the aftermath of conflict even before the virus struck.
There is one more note of caution in this tale: making sure the storm has really passed.
The director of the US Centers for Disease Control and Prevention, Dr Tom Frieden has warned that Ebola is like fighting a forest fire - "leave one burning ember, one case undetected, and the epidemic could re-ignite."
As an example, he described how at one stage it had been thought that every case in Nigeria had been identified, when it turned out that one had been missed, resulting in a new cluster of cases in Port Harcourt.
That incident has now passed and the country remains on course to complete the required 42 days to be clear.
But with the WHO judging that as many as 15 African countries are at risk, these remain anxious times.
And a new concern is emerging among specialists: that the scale of the outbreak is now so large and so spread over so many areas, that following Nigeria's example of tracking down literally every case may never be possible, which means the disease may linger, sometimes unseen, sometimes not, for decades to come.