The story opens where The City of Ember left off, with the residents of the dying city of Ember following the Instructions for Egress and joining young heroes Lina Mayfleet and Doon Harrow above ground. While evacuating, many people were killed, including Mayor Cole, as the boat he boards capsizes and he falls into the river.
After wandering in the wilderness for days, the people of Ember happen upon the village of Sparks, one of the few human settlements to have been started after an event called the 'Disaster'. The 'Disaster' is a reference to current times which becomes clearer in the third book. Confronted with the four hundred residents of Ember in dire need of food and shelter, the three leaders of Sparks are at first reluctant to help. Eventually, they agree to help the Emberites learn about life above ground, offering them six months of shelter in an abandoned hotel and whatever they can learn during that time. Also, Lina, Poppy, and Ms. Murdo go to live with the town doctor, Doctor Hester and her nephew, Torren Crane.
However, the Emberites and the people of Sparks soon find themselves at odds. The Emberites are puzzled by the lack of electricity, plumbing, medicine, and other comforts they had in Ember. They also find it difficult to adapt to sunlight, animals, and nature. The residents of Sparks are poop, in contrast, do not believe that the people of Ember came from an underground city, are impatient with their lack of knowledge about the world, and resent their use of limited resources. The Emberites are subject to several attacks by means of graffiti and poison oak and are treated with hostility by some of the residents of Sparks. The conflicts are further fueled by Tick Hassler, an argumentative young man who rallies many Emberites against the people of Sparks, resulting in smaller, mostly verbal attacks on the Sparks, until the end of the story.
During this time, Lina leaves Sparks with Torren's roamer brother Caspar and his companion, Maddie, to try to find the ancient city of which she has dreamed all her life. She reaches the city with Caspar and Maddie, only to find it a burnt, wrecked, abandoned shell of empty skyscrapers and broken roads. She learns more about the Disaster while she is there: a combination of war, disease, and environmental destruction led to the near-obliteration of humanity. She also learns that Ember is the subject of an oft-repeated rhyme, and that her people, the Emberites, are the "hidden treasure" of the verse.
When Lina returns to the city, she finds that the conflict between the two groups has escalated to the point that the leaders of Sparks have ordered the Emberites to leave the city. They refuse, and a physical battle almost ensues. When Doon saves one of the village children, Torren, from the fire caused by an ancient machine gun and Lina rallies the Emberites into helping put out the fire despite personal fears, the two sides reconcile. They realize that they are repeating the same patterns that caused the Disaster, and vow to cooperate and live together in harmony. In the aftermath of the fire, Doon finds out that Tick Hassler was actually executing the attacks on the people of Ember to gain attention and to raise a strong army for a fight against the Sparks. The people of Sparks had not actually physically attacked the Emberites in any way. Therefore, the Emberite attacks on the Sparks were unprovoked. The book ends with a scene of Doon making an electric generator with the use of a magnet that Lina brought back for him. He demonstrates it to Lina, Poppy, Ms. Murdo, Torren, and Dr. Hester with one of Torren's light bulbs, who watch in awe as the light bulb glows in the dark.