As Hela's powers increase, the only way for the Asgardians to survive is by evacuating their homeworld on the giant ship stolen from the Grandmaster by Korg and the other gladiators. Thor, now blinded in one eye by Hela, realises they can't stop her themselves, so must cause Ragnarok to destroy her and save Asgard - the people matter more than the place.
Loki flies to the vault where Surtur's crown is stored, and places it into the eternal fire. This restores the demon to his full mountainous size, and he starts laying waste to Asgard, including killing Hela. Thor escapes with the others. Loki appears on board - Thor initially believes as a magical projection, but soon realises Loki has actually come to join them. He's still untrustworthy as ever of course, having already tried to betray Thor earlier, and he gave the infinity stone in Odin's vault a lingering glance as he passed it, so probably took that with him.
The ship sets course for earth, with the Asgardians looking to Thor as their new king. However a vast ship descends above them, almost certainly belonging to Thanos, setting up the events of Avengers: Infinity War.
In a scene after the credits, the Grandmaster returns to the surface of Sakaar while the population is still rebelling, and attempts to calm them down by calling a tie between his forces and theirs.