What went wrong in this position? What can I do to improve my gameplay with the black pieces?

There's a lot of small things I could turn into a lesson, but here are some of the larger points:
5...Be6? was a mistake, but it was difficult to find a good move here. This move loses a pawn if it goes: 5...Be6? 6. Nxe6 fxe6 7. Bxe6, but I imagine you saw the pressure on f7 and couldn't find a way to hold. A thematic defense to these attacks is ...d5! In this case, it could work such as 5...d5! 6. exd5 cxd5 7. Bb3 Nc6 and black just continues to develop pieces while holding control of the center.
11...cxd5 would have been better because it replaces your pawn duo in the center. Again, this is one of the key opening principles:
https://www.chess.com/blog/KeSetoKaiba/opening-principles-again
14...Bg5? would lose material if lots of trades happen on g5.
16...Qd6?? was the last big error because it hangs the a6 knight. Better would have been 16...Nc5 to save the attacked knight, or fancier would have been 16...Bxc1 17. Rxc1 (to decoy their rook from attacking a6) and then you have time to relocate the knight such as 17...Nc7.
