After another unsuccessful search for Teyla, Sheppard 'gates home to Atlantis to discover that the city is sweltering hot, utterly abandoned, and surrounded by a vast desert. Sheppard is dumbfounded until a hologram of Rodney McKay an aged Rodney McKay welcomes him to the future. A solar flare has interfered with the stargate, causing it to send Sheppard 48,000 years forward in time. He may now be the last human alive in the universe (in defiance of revealed truth).
Sheppard is horrified, especially when the hologram-McKay tells him what happened after his disappearance in the past. Michael killed Teyla and used her baby for genetic research. His army of hybrids swarmed across the galaxy, exterminating the Wraith and killing all humans who wouldn't make good hybrid slaves. Carter and Ronon both died heroically fighting this terrible foe: Carter in an epic space battle and Ronon during an assault on one of Michael's biggest facilities with an unexpected ally, Todd the Wraith, at his side.
Then the I.O.A. put Richard Woolsey in charge of Atlantis. Keeping only a meager team in place to study the city itself, the bureaucrat allowed Michael to dominate the rest of the galaxy. Disgusted, McKay and Keller both returned to Earth. They fell in love, but their happiness was short-lived. Keller came down with a fatal disease as a result of exposure to the Hoffan drug, whose ravages she had struggled to stop in the Pegasus galaxy. After she died, McKay, grief-stricken, devoted 25 years of his life to bringing Sheppard home in order to rewrite the timeline that had gone so wrong.
McKay had arranged for this hologram of himself to greet Sheppard, seal him into a stasis pod to keep him from aging, and monitor the planet's sun for centuries until just the right solar flare appears to send Sheppard back to his own time. The plan isn't without risks. Power may run out before the flare arrives, stranding Sheppard forever. Also, the corridor to the stasis pods is blocked with sand. Sheppard can only reach the pods by detouring outside the city, into a rising sandstorm. He barely survives. Back inside, he wearily follows McKay to the stasis pods. The hologram-McKay tells him the location where Teyla was imprisoned when Michael killed her. Then McKay seals Sheppard into the stasis pod to wait.
In the past, twelve days after Sheppard disappeared, he arrives back in Atlantis through the stargate. The hologram-McKay's plan worked perfectly. Once Sheppard's astonished teammates are satisfied that he's for real, he leads them on a raid of the facility where Teyla will soon die. Unfortunately, Teyla isn't there, and the place is booby-trapped. As the building blows up around his team, it looks like Sheppard has run out of time, after all.