(Note the description implies a full paragon path, alternate outcomes listed below.)
Before Mass Effect 2
Legion's construction in Geth space was meant to serve as an Infiltration unit in organic space. Legion is a self network of 1,183 Geth programs who operate on a unique mobile platform (his body). Legion's head contains several flaps to simulate eyebrows to better communicate with organic life.
Legion was tasked with traveling outside the Perseus Veil and finding Commander Shepherd since he opposed the heretic Geth and the Old Machines (Reapers). Legion, in an effort to find Shepherd, traveled to numerous sites the commander visited during the his investigation of the rogue Spectre Saren Arterius.
Legion visited Eden Prime, Therum, Feros, Noveria, Virmire, Illos, and several uncharted worlds before finding the original Normandy's crash site on Alchera. While on Eden Prime, Legion was attacked by Alliance soldiers and sustained a rifle shot to his chest.
This left a large hole which he patched with N7 Armor from the crash site on Alchera. This armor was Shepherd's own armor and when questioned why he didn't patch it sooner Legion responds with "no data available" implying the decision was irrational and not usual of the Geth, further showing off its uniqueness.
Mass Effect 2
The Derelict Reaper
Legion is first encountered by Shepherd and the crew of the Normandy SR-2 on board a derelict Reaper orbiting Mnemosyne, a brown dwarf. Shepherd was there to find an IFF device in order to penetrate the Omega 4 Relay and Legion was there in order to gain further information on the Reapers. Legion was surprised to see Commander Shepherd alive and saved the group from a husk ambush. Legion was the first Geth to speak to Shepherd.
When Shepherd arrived at the Mass Effect Generator core Legion was already working on the console but was attacked and deactivated by a husk. Shepherd and the crew destroy the core and take Legion's deactivated mobile platform aboard the Normandy for study since Legion was not acting like the Geth Shepherd had seen before. Legion was stored in the AI Core of the Normandy SR-2. Miranda Lawson was in favor of sending the Geth to Cerberus for an active cash bounty while Jacob Taylor wanted Legion destroyed.
Shepherd had Legion reactivated while EDI erected additional firewalls to prevent hacking. Legion shows no hostility towards Shepherd and requests to join his team in fighting the Collectors and Reapers. Legion does not have its name yet and when Shepherd asks he simply says Geth. EDI quotes the Bible Gospel of Mark 5:9 "We are Legion for we are many." This is suited as an "appropriate metaphor" and Legion gets its name.
When speaking to Legion it will either answer with a very straight forward one word answer or if sentences are needed they will be highly organized thoughts. Legion will speak about the Geth heretics and how the Reaper, Sovereign, swayed them to his side. Legion will discuss topics about its own Geth and the "Morning War". Legion will playback the first recording of a Geth asking if he had a soul which frightened the Quarians into trying to exterminate the Geth. Legion's last conversation details how the Geth are constructing a massive station with the closest human analog being a Dyson Sphere so all Geth programs can be uploaded and never be alone again.
A House Divided
Legion will go to Shepherd with an urgent request concerning the Geth heretics. The heretics had developed a Reaper based virus in order to corrupt Geth and turn them into followers of the Reapers. Legion explains that the virus causes errors in their most basic run times and changes all higher thought processes.
The virus is housed in a space station between stars because organics have no reason to look there. Legion needs the stealth system of the Normandy in order to get close to the station. The Normandy's stealth drive is particularly effective on Geth craft since Geth do not use windows, considering them a structural weaknesses.
Shepherd and Legion infiltrate the Geth Station and Legion brings up the point that since the virus is complete Legion could re-purpose it to brainwash the heretics back into the Geth. Since this is new data Legion takes the mission to process and reach a consensus.
During the mission Legion finds evidence that the heretics have run times in the Geth networks and are spying on them. This confuses Legion as the heretics were allowed to leave and the nature of Geth is to share all data and knowledge. It does not make sense why the heretics would spy on the true Geth. Once in the Central Station chamber Legion poses the question of whether to rewrite the heretics or blow the station to Shepherd. Legion is split between the issue with 573 programs favor rewriting and 571 favor deletion.
Legion says Shepherd has perspective the Geth lack since he has fought the heretics. Shepherd not wanting to kill the Geth has them rewritten and the team evacuates before a large EMP of 1.21 petawats fires through the station and travels through FTL channels.
The Collector Base and Beyond
Legion traveled with Shepherd and the rest of the crew to the Collector base and assaulted it alongside the rest of the Normandy crew. After Shepherd was asked to return to Alliance space to answer for the death of 300,000 Batarian colonists, Legion left to return to the Perseus Veil and report to the Geth consensus. The Geth then began to prepare for war with the Reapers while finishing construction of their Dyson Sphere like housing.
While construction was nearly complete the Quarian fleet began a war to retake Rannoch and bombed the structure, not knowing what it truly was. This caused the death of a large number of Geth programs. Since Geth network to gain intelligence, this greatly narrowed the Geth's perspective and survival became a priority. The Geth accepted an offer from the Reapers. The Reapers uploaded their own code to increase the intelligence of the Geth and their fighting ability while the Reapers maintained control of the Geth.
The Reapers played the signal through a Geth Dreadnought of considerable size. Legion was against this decision but was used as a booster for the signal and placed inside a machine on the dreadnought. The Geth fleet could now fight off the Quarian assault and had them trapped inside the system as they covered the Mass Relay.
Mass Effect 3
Commander Shepherd first re-encounters Legion when the Normandy's crew infiltrates the Geth Dreadnought and frees it from the Reaper machine. Though some newer squad members will express negative feelings over Shepherd knowing a Geth by name they free him and Legion disables the Dreadnought's weapons, shields, and kinetic barriers. The mission was to disable the Dreadnought so the Quarian fleet could flee and join the war effort.
Admiral Han'Gerrel vas Neema instead has the Quarian Heavy Fleet bombard the Dreadnought in order to destroy it, almost killing Legion and Shepherd who use a Geth fighter to escape. This ruins the Quarians' chance at retreat. Legion then accompanies Shepherd aboard the Normandy where it meets Admiral Raan who is distressed at the sight of the Geth and Admiral Xen who wants to dissect Legion. Legion will show the Admirals and Shepherd how the Reaper code has upgraded the Geth and that Geth units can now be considered alive.
The Geth themselves find this "Beautiful." Legion will also state that while he is no longer broadcasting the Reaper signal there is a short range signal coming from Rannoch itself. Legion spends his time in the Normandy's War Room trying to locate the Reaper base where the signal is broadcast.
Legion will reveal a Geth Fighter Squadron hub to Shepherd and the Admirals. Saying its destruction would help the Quarian liveships survive the battle. The Admirals approve of the destruction of the server hub and Legion accompanies Shepherd on this mission.
During the shuttle ride down, Legion reveals the mission involves Shepherd actually going inside the Geth consensus virtually through an interface adapted from Cerberus' Project Overlord. Inside the Geth consensus, Shepherd sees important events in Geth history, such as the first Geth to come online and receive the Geth name, the Geth first proposing the question of his soul, the first Geth to pick up a weapon, Quarian sympathizers protecting Geth from Quarian police, the Geth allowing the Quarians to leave Rannoch, and Shepherd agreeing to work with the Geth.
When Shepherd asks why the last one is important, Legion reveals that Shepherd was the first organic to cooperate with the Geth since the "Morning War" 300 years ago and that the Geth did not want to forget it. Once Shepherd takes the hub offline, the Geth Fighters stop attacking Quarian liveships and Legion reveals there was a secondary purpose to the mission. Legion was able to convince Geth programs to join its cause and upload into powerful Geth Prime mobile platforms. These Prime are sent to Admrial Hackett of the Alliance for support.
Legion is able to locate the Reaper base and accompanies Shepherd on the mission. Shepherd takes a targeting laser to pinpoint a vital area the Normandy can hit. During the shuttle ride, Legion reveals he has some of the Reaper code inside himself so he can counteract any defensive measure the Reapers have put in place. Legion displays a level of shame over this, though he realizes the benefits. Legion separates from Shepherd's team to disable defenses and acquire an escape vehicle. Throughout the mission, Legion disables base defenses and guides Shepherd to an area where he can paint the target.
Once Shepherd has the Normandy strike the base, it is revealed the signal is coming from an actual Reaper. Legion drives a Geth land vehicle while Shepherd mans the guns, firing at the Reaper. Shepherd will use the targeting laser linked to the Quarian Heavy Fleet to destroy the Reaper. Once done, the Quarians begin attacking the disabled Geth ships and Legion proposes using the Reaper code to upgrade all Geth into true AI's. Tali'Zorah will adamantly vote against this as the Geth will fight back and destroy her people. Shepherd allows Legion to upload the code while he and Tali convince the Quarian fleet to stand down. This allows both fleets to survive. Legion at 80% upload will note that it is not enough and upload its own personality to complete the transfer.
In Legion's last moments it refers to itself as "I" instead of "we" showing that it has become an individual instead of an avatar of the Geth consensus. Legion "dies" on Rannoch saving the Geth and giving them their intelligence. A Geth prime then approaches Shepherd, Tali, and Admiral Raan and says the Quarians are welcome to return to Rannoch and the Geth will honor both Legion and its promise to help Shepherd retake Earth from the Reapers.
Legion is a gestalt intelligence and an avatar of the Geth Consensus. Legion is a combination of 1,183 Geth programs loaded onto a unique mobile platform. Legion as a squad mate is a tech type character who can release drones to aid in battle while wielding an assault rifle and sniper rifle.
Legion is shown very proficient with the sniper rifle as his machine reflexes are much faster than those of an organic. Legion is very durable, being able to survive an Alliance rifle shot that ripped a clear hole in his chest and still continue as if nothing happened with only basic patchwork.
Mass Effect 2
Legion can have several fates in the game. When Legion is first acquired, Shepherd may turn it over to Cerberus for a large cash bounty in which case Legion will appear on the Cronos Station as a Legion Assassin under Cerberus control wielding an M-13 Raptor sniper rifle and must be killed by Shepherd.
Alternatively, Legion can die during the suicide mission against the Collector base. In either case a Geth VI based on Legion before he found Shepherd will take its place, and peace between the Quarians and Geth will be impossible, forcing Shepherd to choose a side.
Mass Effect 3
If Shepherd chooses to have Legion upload the code, but cannot convince the Quarians to stand down then the know Intelligent Geth will destroy the Quarians. If Shepherd chooses to side with the Quarians, then Legion will attack Shepherd and grab him by the throat reminiscent of Saren in the original game. Legion will then be either stabbed by Tali, or if she is dead, shot by Admiral Xen's shotgun.