In Norse mythology, Útgarða-Loki (Anglicized as Utgarda-Loki and Utgard-Loki) was the ruler of the castle Útgarðr in Jötunheimr. He was one of the Jötnar and his name means literally "Loki of the Outyards", to distinguish him from Loki, the companion of Thor.
In the Prose Edda book Gylfaginning (chapter 44), the enthroned figure of Third reluctantly relates a tale in which Thor, Loki and Thor's servants, Þjálfi and Röskva are traveling to the east. They arrive at a vast forest in Jötunheimr, and they continue through the woods until dark. The four seek shelter for the night and discover an immense building. Finding shelter in a side room, they experience earthquakes through the night. The earthquakes cause all four to be fearful, except Thor, who grips his hammer in defense. The building turns out to be the huge glove of Skrýmir, who has been snoring throughout the night, causing what seemed to be earthquakes. The next night, all four sleep beneath an oak tree near Skrýmir in fear.
Thor issues blows to the sleeping Skrýmir while the group looks on in an illustration (1842) by Friedrich Ludwig von Maydell [de].
Thor wakes up in the middle of the night, and a series of events occur where Thor twice attempts to destroy the sleeping Skrýmir with his hammer. Skrýmir awakes after each attempt, only to say that he detected an acorn falling on his head or that he wonders if bits of tree from the branches above have fallen on top of him. The second attempt awakes Skrýmir. Skrýmir gives them advice; if they are going to be cocky at the castle of Útgarðr it would be better for them to turn back now, for Útgarða-Loki's men there won't put up with it. Skrýmir throws his knapsack onto his back and abruptly goes into the forest and "there is no report that the Æsir expressed hope for a happy reunion".
The four travelers continue their journey until midday. They find themselves facing a massive castle in an open area. The castle is so tall that they must bend their heads back to their spines to see above it. At the entrance to the castle is a shut gate, and Thor finds that he cannot open it. Struggling, all four squeeze through the bars of the gate, and continue to a large hall. Inside the great hall are two benches, where many generally large people sit on two benches. The four see Útgarða-Loki, the king of the castle, sitting.
Útgarða-Loki says that no visitors are allowed to stay unless they can perform a feat. Loki, standing in the rear of the party, is the first to speak, claiming that he can eat faster than anyone. Loki competes with a being named Logi to consume a trencher full of meat but loses. Útgarða-Loki asks what feat the "young man" can perform, referring to Þjálfi. Þjálfi says that he will attempt to run a race against anyone Útgarða-Loki chooses. Útgarða-Loki says that this would be a fine feat yet that Þjálfi had better be good at running, for he is about to be put to the test. Útgarða-Loki and the group go outside to a level-grounded course.
At the course, Útgarða-Loki calls for a small figure by the name of Hugi to compete with Þjálfi. The first race begins and Þjálfi runs, but Hugi runs to the end of the course and then back again to meet Þjálfi. Útgarða-Loki comments to Þjálfi that he will have to run faster than that, yet notes that he has never seen anyone who has come to his hall run faster than that. Þjálfi and Hugi run a second race. Þjálfi loses by an arrow-shot. Útgarða-Loki comments that Þjálfi has again run a fine race but that he has no confidence that Þjálfi will be able to win a third. A third race between the two commences and Þjálfi again loses to Hugi. Everyone agrees that the contest between Þjálfi and Hugi has been decided.
Thor agrees to compete in a drinking contest but after three immense gulps fails. Thor agrees to lift a large, gray cat in the hall but finds that it arches his back no matter what he does, and that he can only raise a single paw. Thor demands to fight someone in the hall, but the inhabitants say doing so would be demeaning, considering Thor's weakness. Útgarða-Loki then calls for his nurse Elli, an old woman. The two wrestle but the harder Thor struggles the more difficult the battle becomes. Thor is finally brought down to a single knee. Útgarða-Loki said to Thor that fighting anyone else would be pointless. Now late at night, Útgarða-Loki shows the group to their rooms and they are treated with hospitality.
The next morning the group gets dressed and prepares to leave the keep. Útgarða-Loki appears, has his servants prepare a table, and they all merrily eat and drink. As they leave, Útgarða-Loki asks Thor how he thought he fared in the contests. Thor says that he is unable to say he did well, noting that he is particularly annoyed that Útgarða-Loki will now speak negatively about him. Útgarða-Loki, once the group has left his keep, points out that he hopes that they never return to it, for if he had an inkling of what he was dealing with he would never have allowed the group to enter in the first place. Útgarða-Loki reveals that all was not what it seemed to the group. Útgarða-Loki was in fact the immense Skrýmir, and that if the three blows Thor attempted to land had hit their mark, the first would have killed Skrýmir. In reality, Thor's blows were so powerful that they had resulted in three square valleys.
The contests, too, were an illusion. Útgarða-Loki reveals that Loki had actually competed against wildfire itself (Logi, Old Norse "flame"), Þjálfi had raced against thought (Hugi, Old Norse "thought"), Thor's drinking horn had actually reached to the ocean and with his drinks he lowered the ocean level (resulting in tides). The cat that Thor attempted to lift was in actuality the world serpent, Jörmungandr, and everyone was terrified when Thor was able to lift the paw of this "cat", for Thor had actually held the great serpent up to the sky. The old woman Thor wrestled was in fact Old Age (Elli, Old Norse "old age"), and there is no one that old age cannot bring down. Útgarða-Loki concludes by telling Thor that it would be better for "both sides" if they did not meet again. Upon hearing this, Thor takes hold of his hammer and swings it at Útgarða-Loki but he is gone and so is his castle. Only a wide landscape remains.