Odin (Anthony Hopkins) was one of the most powerful beings in the Marvel Cinematic Universe so how was Loki (Tom Hiddleston) able to trick him and usurp the throne of Asgard in Thor: Ragnarok.
As the Allfather, Malekith (Christopher Eccleston) and the Dark Elves.
In order to regain the throne of Asgard, Loki somehow enchanted Odin and sent him to Earth despite the Norse god-king being far more powerful. Odin lost his memory and Loki left him at the Shady Acres Care Home in New York City while the God of Mischief posed as the Allfather and commissioned whimsical plays in Loki's honor. When Thor returned to Asgard in Ragnarok, he forced Loki to take him to Odin on Earth, but they found the retirement home destroyed and Odin missing. Doctor Strange (Benedict Cumberbatch), who was keeping tabs on Odin, sent the brothers to Norway, where Odin was waiting to say farewell to his sons before he surrendered his life force and entered Valhalla. While the exact circumstances of how Loki was able to manipulate Odin to begin with aren't spelled out, there are numerous clues that Odin was already diminished and nearing the end of his life in Thor: The Dark World.
Odin, due to his age, would still never be what he was in his youth. Odin even scolded Loki in The Dark World that, "We are not god! We're born, we live, we die, just as humans do!" So, as powerful as Odin may have been, the one-eyed patriarch was undeniably in decline and musing over his own mortality.
Consider also that after thousands of years of Asgard being peaceful and inviolate, the crown jewel of the Nine Realms suffered multiple incursions and disasters in just 6 years' time. The Frost Giants invaded and stole the Casket of Ancient Winters in Thor, the Dark Elves attacked and murdered Frigga in The Dark World, and Hela conquered Asgard only for Odin was at his full power. The Frost Giants and Dark Elves rampaging in Asgard point to Odin no longer being at the peak of his abilities as King, which was the perfect time for Loki to make his power play in The Dark World.
Finally, Thor even noted that Odin was filled with grief and rage after Frigga was killed by Malekith. Consumed by his failures and the loss of his beloved queen, the Allfather was at his lowest ebb — which Loki was obviously aware of and took full advantage of. At that point, it didn't matter how powerful Odin may have been compared to Loki, he was emotionally vulnerable and easy prey for the God of Mischief. And, maybe on some deeper level, Odin wanted to remain in exile. Regardless, when Odin came to his senses and realized Loki had tricked him, he must also have realized that his time as Allfather really was over and Odin was ready to let Thor be the King he was born to be.