The story begins in the Land of Departure, where a trio of friends and Keyblade wielders—Terra, Aqua, and Ventus (Ven for short)—train under the Keyblade Master Eraqus to become Keyblade Masters themselves. Terra and Aqua take an exam to achieve the Mark of Mastery, but only Aqua passes while Terra fails due to the darkness in his heart. Shortly after the test, Master Xehanort disappears, and a horde of mysterious creatures called the Unversed begin to appear throughout the worlds. Eraqus learns from the sorcerer Yen Sid that the Princesses of Heart are in danger from the Unversed, and orders Terra and Aqua to destroy the Unversed and find Xehanort. Ven is driven into following Terra against Eraqus' wishes by Vanitas, Xehanort's apprentice, and Aqua is sent to watch over Terra and bring Ven back to the Land of Departure.
Upon arriving in several worlds, Terra, Aqua, and Ven encounter various Disney characters, fighting off many Unversed along the way. One of the characters they meet is Mickey Mouse, the apprentice of Yen Sid, who is also on a mission to destroy the Unversed, albeit against Yen Sid's wishes.Terra ends up attracting the attention of several Disney villains, who offer him the whereabouts of Xehanort in exchange for assistance in their own agendas. Upon finding Xehanort, Terra is instructed by him to destroy Vanitas, as he is revealed to be the Unversed's source.The three briefly reunite at Radiant Garden where Aqua and Ven confront Terra about his actions, but he leaves to continue Xehanort's mission.
Ven comes across Xehanort, who reveals his intentions to use Ven's heart and fuse it with his other half, Vanitas' heart to create a final Keyblade known as the χ-blade. He sends him to the Land of Departure to confront Eraqus, saying he knows the truth about him. Eraqus tries to kill Ven to prevent Xehanort's plans from succeeding, but Terra, who was also sent to the Land of Departure by Xehanort, faces Eraqus to protect Ven.Upon his defeat, Eraqus is vanquished by Xehanort, who covers the Land of Departure in darkness and tells Terra to go to a world known as the Keyblade Graveyard, threatening him about his friends' fates. Ven is similarly instructed to do the same by Vanitas, as is Aqua by Yen Sid after he informs her of Eraqus' death.
Terra, Aqua, and Ventus gather at the Keyblade Graveyard, where Xehanort appears with Vanitas and reveals his plan to use the χ-blade to unlock Kingdom Hearts and unleash the secrets of the Keyblade War onto the various worlds. In the following battle, Xehanort takes over Terra's body as his heart is swallowed by darkness, but Terra's will remains within his discarded suit of armor, which comes to life as the Lingering Sentiment and defeats Xehanort. Meanwhile, Ventus is forced to fuse with Vanitas to create the χ-blade and battles Aqua alongside Mickey while the real Ven engages Vanitas in a metaphysical battle within his mind.Aqua shatters the χ-blade as Ven destroys Vanitas from within, though Ven's heart is sent into a deep sleep as a result.
Upon learning that Ven will not awaken, Aqua brings his body to the ruins of Land of Departure, where she seals the world's keyhole and transforms it into Castle Oblivion to ensure Ven will not be disturbed. Aqua then goes to Radiant Garden, where she fights Xehanort, who still possesses Terra's body. The battle rages until Terra's presence manifests, resulting in Xehanort unlocking his own heart and falling into the Realm of Darkness. Aqua saves Terra but becomes trapped in the Realm of Darkness in the process. Xehanort, who has lost his memories, is discovered and taken in by Ansem the Wise, ruler of Radiant Garden, as his apprentice. Ven's heart then reconnects to young Sora's and is able to rest within his heart. In the game's secret ending, which takes place after the events of Kingdom Hearts II, Aqua comes across Ansem the Wise in the Realm of Darkness and learns from him about Sora, who has the power to save those connected to his heart, including Terra, Ventus, and Aqua herself. Sora, having learned of their fates from King Mickey, decides to undertake another quest in order to find and save them