Comamnder Shepard first found legion on a mission against the collectors. Legion was injured by a husk but, Commander Shepard's team transport him in the normady. Legion is revived by Comamnder Sheaperd. Legion becomes your ally and is part of a group called the True Geth that are enemeis to the heritics which were the geth that Comamnder Shepard battled in Mass Effect 1 and 2.
Legion helps you in Mass Effect 3 and gets a platoon of geth primes to join Legion. If you allow Legion to he will sacrafice himself which will allow the geth to become more intelligent then, they will wipe out the majority of the Quarian population in a battle. Then you will gain a new stronger ally ( the entire geth population ) now smarter than ever before or you could allow Tali or a quarian admiral to blast Legion with a shotgun.