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 Grand Master by Korg and the other escapees. 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 Asguard, 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.