The city of Ember was created to protect survivors from the aftermath of wars and plagues.
The cause of the war isn't revealed in the first book. A major plot point of The City of Ember is that the people in the city don't know what happened to cause their ancestors to move to Ember. They only know that the electricity is going out and they'll be left in darkness. The city wasn't meant to survive forever—the citizens were supposed to go back to the surface when it was safe.
After the citizens emerge from the city, in a sequel to the first book, they find out that Ember was created because there was a war. Bombs were dropped on the cities and burned them to nothing. The survivors were then afflicted with a plague that killed many people.
According to Torren Crane in The People of Sparks, there were four wars and three plagues in total.
In the novel The City of Ember, the city is created as a result of an undisclosed historical cataclysm—essentially some apocalyptic event that has ravaged the earth and its resources, necessitating an underground city running on some form of machinery. The earth was presumably destroyed in some sort of nuclear war which destroyed its resources and natural land, making it inhospitable for human life, but only temporarily. The intention of the city was to last long enough for the earth to become habitable again.
The city was constructed in such a way that it would be viable for a certain period of time only. By the end of that time, it was hoped, the inhabitants would have figured out how to survive on the surface of the planet, or the conditions would have improved enough for the planet to be habitable.
The city of Ember was created for one main reason: the preservation of the human race. The people who lived on the planet's surface concluded that a nuclear war of epic proportions or some other similar apocalyptic disaster would eventually and inevitably occur, and, unfortunately, the human race would not be able to survive it. Thus, they decided to build an underground city and equip it with all basic necessities; the city was meant to run on electricity. By building the city of Ember, the people made sure that the human race would continue to exist and evolve. It worth mentioning that the plan actually worked: Ember is described as a city which is over two hundred years old.
The city of Ember was created in the aftermath of an apocalypse, presumably a nuclear war. The war had rendered conditions on the face of the earth unlivable, so Ember was built far beneath the ground to allow survivors of the war to continue to thrive. Ember is the sole refuge remaining for the human race. Because it is located so far beneath the earth's surface, it is completely dark, and it is sustained by a complicated and ingenious system run by electricity. At the time of the story, over two-hundred years after the Ember's inception, the city is threatened because it appears that the electrical system is about to give out. If it fails completely, the city will be plunged back into complete darkness.
Ember was not intended to last forever. Its creators had estimated that, after a certain amount of time, conditions on the earth would improve to where it would be able to sustain life once again. These founders had written instructions as to how the people could escape from Ember when that time came, and the instructions had been placed in a box which was to have been passed down from mayor to mayor of the city. Unfortunately, after a number of years, the box had been lost, and ultimately forgotten. Now that the electricity system is threatened, the people are stuck in the doomed city with no way of escape.