One hundred years ago, a mysterious Pokémon appears out of a ring and attacks a village. It summons a few 
Legendary Pokémon, and defeats them easily. A mysterious traveler then manages to trap the mysterious Pokémon into a bottle, causing all the summoned Legendary Pokémon to return from where they came. The Traveler disposes of the bottle properly, hoping that the Pokémon will never be released from its prison. Years later, a man finds the bottle but is suddenly possessed by an enraged spirit when touching it. Meanwhile, in a resort out in the desert, Ash and his friends are frolicking in the sun, eating Serena's donutshaped Poké Puffs. Suddenly, a mysterious ring appears from nowhere and a hand comes out, grabbing Chespin's donut and replacing it with a Tamato Berry. Chespin didn't realize the switch, and eats it, the spicy flavor causing it to overheat so much, Bonnie thinks it learned Flamethrower. Ash then notices multiple rings popping out of nowhere, grabbing all the donuts. He attempts to apprehend the culprit, but manages to get pulled into a ring, himself, along with Pikachu. The pair soon realize that they now are in Dahara City. The prankster reveals itself to be a talking Hoopa, and Ash introduces himself and Pikachu to it. Always a prankster, Hoopa insists on calling Ash 'Ashkan' and Pikachu 'Pikan'. Soon, Hoopa decides that it wants to show off its power to the two, and summons a large horde of Pikachu, including five Cosplay Pikachu, from its Ring. Hoopa then makes a game of this and asks Ash which is his 'Pikan', and Ash easily picks up the right one. Hoopa is sad, saying "Hoopa lost." Eventually, one Pikachu gets excited, causing all the others to do the same, and all of the Pikachu electrocute Ash and Hoopa. A woman approaches the three and lectures Hoopa on his behavior, but gets electrocuted as well. She soon introduces herself as Meray and soon, thereafter, Ash asks Hoopa to make a ring to get to his friends, to which Hoopa excitedly agrees to do so. Ash reaches through and gets the group to Dahara City. The group then decide to go to Dahara Tower, the same place where Meray was going. However, when they ask Hoopa if they can make the trip shorter by using its rings, it forgets that it can't go into its own rings just yet, so the team decide to move on foot.
During their walk, the possessed man from before releases the dark aura from the Prison Bottle, transforming Hoopa into the same monster that attacked the village 100 years ago. The transformed Hoopa targets the Bottle, and throws a building at it, but Pikachu swiftly counterattacks with Thunderbolt, shattering it and sending Team Rocket, who had been spying on the group for a while, blasting off. The man is released from his spell, and Hoopa reveals its forthcoming demise. The man, revealed to be Meray's brother Baraz, picks up the Bottle, and traps the dark aura once more. After everything has settled, Baraz reveals that 100 years ago a Pokémon, similar to Hoopa, appeared out of a ring, only wanting to help, but the people sent it away. It was only after offering showers of gold did the town prosper and people began to worship it, even challenging it in battle. However, it soon went mad with power, and was soon stopped by a mysterious traveler. Thus, Hoopa was reborn as a companion to the traveler, offering her seeds and meeting Baraz, becoming like siblings. Team Rocket listens in on the conversation, and plots to steal the bottle for profit.
Later that night, after everyone has fallen asleep, Team Rocket attempts a sabotage. However, thanks to Meowth's ignorance, he becomes possessed, and releases the demon, as it once again attempts to possess Hoopa. Team Rocket swats the bottle away from her, only to inadvertently release a demon called The Fury. The Fury attempts to exterminate Hoopa, but Hoopa summons a Lugia to intercept it so the group can escape. In the ensuing chaos, Baraz finds out that the bottle has been shattered. However, he thinks of a plan to repair it using Serena's Braixen, a wild Hippopotas, and Ash's Frogadier, while Ash and Hoopa go into hiding. While hiding, Ash suggests that Hoopa and The Fury try to get along, only for them to encounter him trying to take Hoopa away. The trio try to escape, but are surrounded and moments before being incinerated, Lugia rescues them, but not before being shot down by The Fury. In anger, Lugia tries to attack him, but The Fury sends him back to the sea, using a Ring.
Hoopa uses its Rings to summon RayquazaLatias and Latios. The three Legendary Pokémon attack The Fury with Dragon Pulse all at once, but to no avail. Ash then notices the tower, and decides they should hide there. But soon they are cornered by The Fury, who blasts them. Afterwards, The Fury goes to attack the city, causing death and destruction. He summons the Dark Ones, Primal Kyogre and Primal Groudon and Kyurem, and an all-out battle ensues between the six Legendaries.
Meanwhile, in Dahara Tower, the group tries to have Braixen, Frogadier, and Hippopotas reforge the bottle, but Palkia arrives and attempts to sabotage the process, but Latios intercepts it with a Dragon Pulse. In the midst, Rayquaza is brutally beaten by Kyurem, who attempts to freeze everything, but is stopped by Rayquaza. Meanwhile, Primal Groudon incinerates buildings with its Flamethrower trying to shoot down Latias. Rayquaza attempts to use Twister around the tower to impede an all-out assault to the group. After most of the city has been decimated, and all of the Legendary Pokemon are gathered at the center of the city, attempting to destroy each other, The Fury tries to kill Ash, but is suddenly stopped by the crack of dawn. Baraz has completed the Prison Bottle, but accidentally drops it. Ash catches it, but is immediately possessed by The Fury. Ash, now possessed, tries to destroy Hoopa, who was freed from the spell, permanently, while Hoopa tries to cleanse him with her memories he had with Baraz, Meray, and the traveler. This stalls the possessed Ash, while the demonic aura begins to liquidate for good. A somewhat freed Ash now has an empathy link with Hoopa, and realizes that the evil one is gone. Out in the distance, the Legendary Pokemon roar (To which Hoopa claims "They were surprised"). However, a void warp was formed, destroying all connections to the city. Pikachu's Thunderbolt proved useless, and the Legendaries' cooperation didn't help so much either. Resigning to their fate, Hoopa suggests that Ash use the Prison Bottle, and Hoopa willingly transforms into a new form called Hoopa Unbound. He helps people escape (including Team Rocket), but as soon as Ash was to go into the ring, it starts to shrink. Baraz and Meray insist that Hoopa and Ash's friends escape, regardless of their fate. However, Hoopa still cannot go into the ring, and inadvertently helps Meray and Ash escape. At the last possible moment, the rift stops, giving them time to escape, but they get stuck in the ring. Hoopa suddenly remembers the traveler's words and considers him family. Hoopa decides to stay, with a narrow escape route for Baraz.
At that moment, the rift was broken, and all that's left was a decimated tower and city. In the sky, everyone notices Arceus staring down at them, then goes to fly away, soon being followed by all the other Legendaries. After all that happened, Clemont suggests they go back to Arche Valley, but Hoopa declines, saying he has unfinished business to do first, and wishes Ash the best of luck on his journey to become a Pokémon Master.