Make sure to stack up on health potions and the likes before going after Ghirahim. Once all the preparations are done, go through the Gate of Time. You'll face a gauntlet-like event. Most of it is pretty straightfoward and the canon-fodder enemies aren't tough. One thing of note is the blue Hobogoblin, who's actualy a much more sophisticated enemy than the others. Once you reach the bottom, the fight starts.
Repeat this three times and he will fall to the ground, pulling out his sword. The ensuing sword duel is by no means easy, Ghirahim has a rather long range to his attacks, and the only way to damage him is to parry his attack with your shield and use the small opening to stab him in his chest. He will shoot shock waves at you from time to time, but they're easy enough to dodge. Just like before, you can block his dagger barrage with your shield. Continue this pattern for a bit, and after a few hits Ghirahim will pull out his final weapon.
Parrying alone won't work anymore as he will block with his broadsword. The tricks is to watch how he angles the sword when he blocks. If it's horizontal - do a vertical spin attack, if it's vertical, do a sideways spin attack. After you chipped away a part of the sword he will switch the angle. Now it's not only important whether you attack it vertically or horizontally, but also which direction you do it from, as you want to avoid hitting the side which you already chipped away at. A third block alteration will occur once you chip away at the other side as well, at which point you just have to hit the core of the blade to shatter it and stun Ghirahim, allowing you to stab him.
Repeat this twice to finally bring him down.
This is now you last chance to stock up on items and repair / upgrade your stuff. Once all the preparations are complete, head through the portal to face Demise.
After a while, the Demon King will infuse his sword with electricity. The basic strategy remains the same, although now you will have to chain parry three times before you are able to get even one hit in. However, just like the boss, you can raise you sword up in the air to infuse it with electricity as well, allowing you to stun Demise and get in a few hits. Be careful of him shooting out his charge in the form of a fast moving lightning blast. You also don't want to be close to him when he raises his blade up in the air, as the ensuing lightning strike will do damage in a small area around him.
Once he falls down, quickly pull off a finishing blow. He will dodge a few of them, just rinse and repeat until a finishing blow connects.
Congratulations, you have beaten The Legend of Zelda: Skyward Sword!