I just want to cover two other situations where underpromotion is necessary to avoid stalemate, one where it is required to promote to a Bishop, and one with a Knight.First, the Bishop.
In this position we should examine the natural promotion to a Queen.
Now black cannot promote
his pawn, and the only move he can make is 3 ... Kh3, allowing the white king to take control of the key squares of the g-pawn, 4.Kf2
Also, if the white pawn was on h5 instead, only promotion to a Rook would win.
Promotion to a Knight.Notice that a Rook here would also stalemate.
So, we must promote to a Knight!
After this series of moves Black must move his king away from the defense of the a-pawn, allowing white to make the move 9.Ka2
So promotion to a Queen isn't always the only way to handle yourself.