After getting past the monster horde, Ghirahim will transform and attack you.
Phase 1: Floating Platforms
Ghirahim will create floating platforms and you have to fight him without getting knocked off the edge. Hit him repeatedly, but jump back if he blocks. Keep hitting him until you knock him off the edge. When he falls down to the lower platform, jump down and do a fatal blow.
In the next phase, use the same strategy. Once he gets close to the edge, he will have purple energy on his hands. Hit in the proper direction to avoid touching his hands. Otherwise, he will knock you toward the edge. If he hits you back, use a shield bash to knock him back again. Repeat this strategy until he ends up on the ground.
Phase 2: Hit the Diamond
Hit Ghirahim's sword until he knocks you back, then use a shield bash. Then do a forward thrust to hit the diamond on his chest. Sometimes he might transport himself behind you.
If you get too far away, he will shoot energy at you. Jump to the side to avoid it. Alternatively, you can hit the energy with your sword by slashing it in the same direction to knock it back toward him. He might knock it back toward you, so be prepared for a dead man's volley.
If he throws daggers at you, knock them back or jump out of the way, or use your shield to block them.
Use this strategy to stab his chest repeatedly.
Eventually, your attacks will destroy the sword that he's holding. Use a forward thrust when this happens.
Phase 3: Break the Sword
Ghirahim will take out a larger sword. Hit it in the short direction to damage it. For example, if he is holding it horizontally, hit it vertically. If you take too long, he will jump back and repair his sword.
Be sure to jump out of the way if he swings the sword.
Once you have destroyed the large sword, do a forward thrust to defeat him.
After this, there will be a long cut scene. Afterward, you can save the game at the bird statue. You can even go back to the gate of time and return to the present to stock up on potions and whatever else you might need.
NOTE: You might want to save and quit, then go to the game select screen and make a copy of your current saved game (choose the game file and press the + button to copy.) You'll see why after you beat the game.
Go back through the gate of time to return to the past and go to the bottom of the pit, and step into the dark circle to begin the final boss fight.