Here's how I understood it, based on what both Smith & the Architect said:
The Matrix was formed because an unoccupied human mind can't survive, and the machines needed us*. The first Matrix was designed to look like a utopia... but humans couldn't accept that, and died or went insane. The machines designed a second Matrix to appear like human civilization just before the rise of the machines, and it worked.
Mostly.
The problem was, the Matrix wasn't perfect. Glitches, like the black cat, caused some people to question the reality of their existence and discover the truth. The machines found it difficult to isolate and eliminate these "rebels," and hit upon an idea. They would allow a few of these people to slip free of the Matrix and form their own enclave, where most of them would be isolated in one place. This became Zion.
As part of the plan, they also introduced the concept of The One. Knowing that the growing numbers in Zion could eventually become a threat, they hit upon an idea to 'cull' the population of Zion every once in a while. One individual would not only be shown the truth, they would be given additional software in the Matrix to allow them even greater power than normal. This person would then lead the rebellion, right up until the pivotal moment where they would be guided into confronting the Architect.
At this point, due to the Architect's guidance, they would be given the choice of either saving humanity as a whole while sacrificing Zion, or trying to fight back in what would become the end of humanity. After they chose to abandon Zion, they would be allowed to pick a certain number of people to begin a brand new Zion, with no knowledge of the previous one. I would assume that, at this point, the One would be killed to preserve the secret.
However, it didn't work right this time. My personal belief is that the Oracle has also been subtly manipulating things, specifically in her teaching of Morpheus and Trinity. This time, the One did things a little differently. Perhaps Neo picked up on his powers a little quicker, or found some quirk in the programming... whatever happened, he awakened to his abilities and managed to alter Smith without fully destroying him. In addition, he fell in love with Trinity, altering his purpose.
That's what led to the breakdown in their plan. With Neo no longer bound by the need to save humanity alone, and the Virus-Smith on the loose, the Machines had lost control of their plan. To them, the only option was to allow the Matrix to be undone and to destroy Zion... but Neo offered them an alternative. In sacrificing himself, he gave the Machines a way to access Virus-Smith's program and essentially find an anti-virus to wipe him out. The price being that they would give up their control of humanity, and work with us to find a way to live together.
* The whole "human battery" thing was a bit silly. From what I understand, the original story involved humanity acting as a huge processing system for the Machines, using our brains to help them have essentially unlimited CPUs... but some executives decided that would go over too many people's heads, and went with the "power source" idea. Bleh.