Prequel trilogy
A younger Yoda appears in the prequel trilogy, beginning with The Phantom Menace (1999). In the film—which is set 35 years before The Empire Strikes Back—Jedi Master Qui-Gon Jinn brings the young Anakin Skywalker to the Jedi Council. Convinced that Anakin is the "Chosen One" of Jedi prophecy who will bring balance to the Force, Qui-Gon requests that the boy be trained as a Jedi. Yoda senses great fear in Anakin, especially in regards to his attachment to his mother Shmi, and foresees "grave danger" in his training. The Council, led by Mace Windu, rejects Qui-Gon's request. When Qui-Gon is mortally wounded in a duel with the Sith Lord Darth Maul, his dying request is that his apprentice Obi-Wan Kenobi train Anakin. Obi-Wan tells Yoda that he will train the boy, even without the Council's approval. Yoda reluctantly gives his blessing to Anakin's training.Attack of the Clones (2002) is set a decade after The Phantom Menace. Yoda is now the Master of the High Council in addition to his position as Grandmaster. He and many other Jedi are concerned about the emergence of the Confederacy of Independent Systems, a secessionist movement seeking independence from the Galactic Republic. After the first attempted assassination of Senator Padmé Amidala, Chancellor Palpatine suggests that she be put under the protection of Obi-Wan, who is training Anakin. At the climax of the film, Yoda saves Obi-Wan and Anakin from the Separatists and defeats his former apprentice, Count Dooku, in a lightsaber duel.
In Revenge of the Sith (2005), Yoda and the Jedi Council pursue the mysterious Sith Lord Darth Sidious. Palpatine has now amassed near-dictatorial emergency powers, and begins interfering in Jedi affairs. The Council orders Anakin to spy on Palpatine, whom he considers a friend and mentor. Anakin seeks Yoda's counsel about his prophetic visions that someone close to him will die. Yoda, unaware that Anakin is referring to Padmé, tells him to train himself to let go of everything he fears to lose. Unsatisfied, Anakin turns to Palpatine, who then reveals himself as Darth Sidious. The Sith Lord manipulates the young Jedi into becoming his apprentice, suggesting that the dark side of the Force can save Padmé from dying.
Sidious transforms the Republic into the Galactic Empire, proclaiming himself emperor and ordering the clone troopers to kill their Jedi generals. Through the Force, Yoda feels the deaths of each of the Jedi as they are betrayed by their own troops. After killing the clone troopers instructed to assassinate him, he escapes with the Wookiee leaders Tarfful and Chewbacca to Coruscant, where he and Obi-Wan fight their way into the Jedi Temple. They discover that all the Jedi inside have been slaughtered, including the children. Yoda and Obi-Wan find a recording revealing that Anakin—now known as Darth Vader—was the assassin. Yoda decides to face Sidious, and sends Obi-Wan to kill Vader. When Obi-Wan protests, Yoda tells him that the Anakin he knew no longer exists. Yoda battles Sidious in a lightsaber duel in the Senate. In the end, neither is able to overcome the other and Yoda is forced to retreat. After Padmé dies in childbirth, Yoda recommends that her infant twins Luke and Leia be hidden from Vader and Sidious; he sends Leia to Alderaan and Luke to Tatooine. At the end of the film, it is revealed that Yoda has been learning the secret of immortality from Qui-Gon's spirit and passing it on to Obi-Wan.