How did I still lose with 1 piece advantage? Throughout the game, I thought I had a positional and piece advantage, but I STILL LOST! 

What did I do wrong? (using Ruy Lopez btw)

[FEN ""]

1. e4 e5 
2. Nf3 Nc6 
3. Bb5 Nf6 
4. Nc3 a6 
5. Bxc6 dxc6 
6. O-O Nxe4 
7. Nxe4 Bg4 
8. h3 Bh5 
9. g4 Bg6 
10. Nc3 Qd6 
11. Re1 O-O-O
12. Ne5 f6 
13. Ng6 hxg6 
14. d4 Rxh3 
15. Kf1 Rh1 
16. Kg2 Qh2 
17. Kf3 Qh3 
18. Ke2 Re8 
19. Kd2 Re8xe1 
20. Qxe1 Rxe1 
21. Kxe1 Qg4 
22. Be3 Bb4


At this point, I surrendered because I'm at a positional disadvantage, my knight is pinned and my rook is still undeveloped. 

I know one weakness of using Ruy Lopez is that your left side develops slowly, but damn! Where did I make a mistake? Was I just unlucky?

EDIT 1:
OMG I just realized he baited my king-side pawns to open up for an attack! >:(

I should've read this article earlier: Keeping Your Castled King Safe
Two things leap out at me:


Moderate error: After 8...Bh5, you're a piece up but you're not done developing and your knight on e4 is unprotected. Reasonable moves (I'm sure there are others) include 9.d3, supporting your knight and allowing your bishop to develop; 9.Re1, centralizing your rook and supporting your knight; and 9.Ng3, kicking Black's bishop and moving your knight to a safe square. Instead you played 9.g4, weakening your king's position and forcing the Black bishop to a place where it attacks your knight.
Huge error: You're still doing OK as of 13...hxg6, but your h3-pawn is under attack. (Note that this wouldn't have been an issue if you hadn't played 9.g4.) The simplest defense is 14.Qf3 but 14.Kg2 is possible too. Instead you let Black's rook capture on h3 and now your king is under severe attack.


You could have defended against the ensuing attack better, but I'm not going to bother with that because the way to win games like these is to not even let it get to that point.