He still manages to spend it all, but then he finds that the witch left him something else, something akin to Aladdin's Lamp: her tinder box.
Using the powers of the tinder box, he has the kingdom's princess brought to him from where her father has been keeping her in hiding. (It was foretold that she would marry a common soldier, and the king can't have that!)
Well, the soldier is found out for gaining access to the princess and is sentenced to hang. The powers of the tinder box, however, save him at the last moment. The king and queen are killed, and the soldier marries the princess after all. And she seems quite fine with it!