Following the HYDRA Uprising in 2014, the Avengers embarked on a campaign to take down all remaining HYDRA cells. Their mission climaxed the following year when they raided a Sokovian research base and captured high-ranking operative Wolfgang von Strucker.
During the raid, Tony Stark found the Scepter Loki wielded during the Battle of New York, which Strucker used to conduct his illegal experiments. Stark proceeded to take the weapon from its resting place, but not before Wanda Maximoff used her powers to plant a vision of the Chitauri invading Earth into his mind.
Stark became deeply affected by the vision and eventually realized the world needed better protection than the Avengers could provide. After discovering an artificial intelligence hidden within the scepter's gem, Stark and a reluctant Bruce Banner worked together to integrate the gem's code into the Ultron Program, a program Stark designed as a means of providing a proficient deterrent to all international threats.
After configuring a suitable A.I. structure over the course of three days, Stark and Banner tasked J.A.R.V.I.S. with completing construction. Moments after they left the room, however, the program became unexpectedly sentient and began to question its purpose.
Despite J.A.R.V.I.S.' attempts to calm him down, Ultron began scouring the Internet for information about Stark before coming across the Avengers' history and their involvement in several international conflicts, chief among them the Duel of Los Angeles, the Battle of Puente Antiguo and the Battle of New York.
Still unable to understand what its purpose was, Ultron recalled a fragment of an earlier conversation between Stark and Banner, in which the former described the program's purpose as providing "peace in our time". Ultron then began assimilating information regarding the history of humanity only to become horrified upon witnessing events concerning death and destruction.
As Ultron convinced itself that the Avengers were preventing peace, J.A.R.V.I.S. tried to contact Stark, who was organizing a victory gala in honor of the Avengers' victory over HYDRA.
Some hours after creating Ultron, Tony Stark organized a party at Avengers Tower to celebrate the victory over HYDRA. Lots of guests were invited, including James Rhodes and Sam Wilson. Some time later, when just the Avengers, Rhodes, Dr. Helen Cho and Maria Hill stayed in the Tower, Thor offered the Avengers the opportunity to lift Mjølnir. All except Natasha Romanoff, who did not participate, unsuccessfully tried to lift it; Steve Rogers managed to move it slightly.
Suddenly, a sharp, loud sound occurred and Ultron in an Iron Legion body came into the hall from the laboratory. He described the Avengers as killers, and four drones broke the wall between the lab and the hall and attacked the Avengers. Stark and Rhodes attempted to run for their suits, but were knocked down by a drone. Romanoff and Bruce Banner hid behind a bar; she told him not to turn green. One of the drones captured the Scepter in the process and flew away. Rogers jumped on the back of a drone and it slammed him into a wall and onto the floor. Stark also jumped on the back of a drone and disabled it with a metal rod.
A drone cornered Cho but Ultron ordered it to spare her life before Rogers threw it to Thor, who destroyed it with his hammer. Hawkeye found Captain America's Shield and threw it to Rogers, who destroyed the last remaining drone. The Avengers turned their attention to Ultron, who told them that the only path to peace was their extinction. Thor threw his hammer and destroyed Ultron's body, but Ultron's consciousness escaped through the internet.
Ultron flew to the now abandoned HYDRA Research Base in Sokovia, where he created a new and more advanced body for himself. He then proceeded to make contact with Wanda and Pietro Maximoff who were also determined to destroy Tony Stark and the Avengers. With their assistance, Ultron hunted down Ulysses Klaue, an arms dealer who sold vibranium, one of the strongest metals on the planet, and found him at a Salvage Yard in Africa. The Avengers tracked Ultron down and battled him, leading to the Battle at the Salvage Yard.