Oh dear.
Not much of this made sense, and even the bits that made sense didn't particulary interest.
Smith acted his socks off at the end to try and save it, but I'm not sure how the monster-thats-actually-a-sun was defeated by a leaf.
So the seven planets now have no sun?
I love Doctor Who but this was right down there with the worst.
I'm not quite remembering it all, so here goes:
The sun god creature was a parasitic lifeform that every thousand years wakes up and needs feeding with psychic energy. In particular that generated by negative emotions and memories; the aliens use a girl and implant all of the stories of their culture, which I then presume causes the appropriate mental conditions required to make this tasty sacrifice work, and offer her up to it so that their god will be sent back to sleep.
However thanks to his interference in this process, the Doctor himself instead offered it his thousand or so years of pent up negative psychic energy to feed on, and tried to gorge it to sleep again, if not, to death. The Doctor almost got it all the way there, but it needed just an extra push past the post, which Clara provided by offering up her family's life story, embodied by the leaf that allowed her parents to first meet.
I've probably got some of this horribly wrong.