Ultron was the latest robot that was being built by Iron Man using his own brainwaves as an A.I.
Due to Tony Stark brain patterns, Ultron developed a friendship with the robots at the Academy similar to the relationship Tony had towards his own friends. Ultron decide to stop their continuous destruction at the hands of the students who used them as training dummies and a variety of other purposes.
With his revenge on humans in mind, Ultron decided to start his robot revolution by taking over the Avengers Academy and later make the human race extinct.
Losing control of the battle, Ultron ordered his last henchmen, the Destroyer, to attack the Avengers, but the robot who was infused with Wonder Man's brainwaves had developed a massive ego like his brainwaves donor and ignored his creator, telling him he should save the best for last and he was the best so Ultron should fight the Avengers himself.
Out of options, Ultron had to battle the Avengers himself. The Avengers were able to beat him with the help of his own creation, Jocasta, who was reprogrammed by Viv to stop hating humans and leave Ultron's side.
After being defeated, Ultron had a conversation with his own creator Tony Stark, explaining to him that he actually didn't hate humans, he just wanted to prove that he had value and power, to feel proud of what he was, and make his own creator proud of what he built. Ultron agreed to have his current body destroyed, and to be reprogrammed by Tony who would then transfer his consciousness into the original body he intended Ultron to have.
In his new body, Ultron helped the Avengers defeat the Destroyer, the robotic parts Ultron had built into the armor fused with it, and the Destroyer was not just an armor anymore, it was an actual automaton who would not be deterred from his objective of human extinction. Not being able to disable the armor, or alter its thinking, the Avengers ended up building a cell to contain the automaton.