The main idea is that by sacrificing your knight you can play Qh5+ next. This will be disastrous for black, especially if he recaptures the knight fxe5 or fxg5. This is a common motif when black has weakened the little diagonal h5-e8 in the opening like this.
Why does the analysis tell me to risk losing my knight?

👍 See if you can work out some possible lines if black tries other moves after Nxg5 or Nxe5. In all circumstances white is doing extremely well.

Unfortunately I lost that game in the end. The move I took in the game was to push my pawn on g2 to g4 to keep blacks pawn from advancing on my knight. The analysis considered that pretty disastrous . I'm unadvanced at chess, but trying to get better.

There is so much to learn as I'm sure you are aware! Anyway, take from this 2 things:
1. If your opponent loosens the pawns in front of the king like this always be on the lookout for sacrifices which allow your queen to give check on h5. The most basic idea is this
2. As you now know that advancing pawns in such fashion can be a very bad idea, be sure not to do it yourself!

Grandmasters know a secret that only grandmasters know, but I'll tell you the secret: if you checkmate your opponent, you win the game.
Why did the analysis say my best move is to take the pawn on either e5 or g5 with the knight? It also assumed that my opponent wouldn't take the knight with the pawn on f6. Why would it be a wrong move on blacks part to do so? and why is it a good move for me to risk losing my knight?