Because the queen is the most powerful chess-piece, it is almost always chosen to replace the promoting pawn. However, promotion to a knight instead can sometimes be useful:
Here, promoting to a queen is only a draw (1. e8Q Qf7+ forces the exchange of queens, and white cannot win with just his bishop), but 1. e8N+ (see algebraic notation) instead wins by virtue of a fork: 1... Kf8 2. Nxc7, and bishop and knight against king is a forced mate.
Because the powers of the rook and the bishop are combined in the queen, there is usually little reason to underpromote to them. The most common cases involve avoiding stalemate:
Here, 1. f8Q is statemate; instead 1. f8R Kh6 2. Rh8 mate. The underpromotion here is not forced - 1. Ke7 will allow white to promote to a queen on the next move if he wants- but it is the quickest way to win.
Underpromotion to knight in practical play is rare, and to bishop or rook is even rarer, but in composed chess problems underpromotion occurs more often. An Allumwandlung is a problem where promotions to all four possible pieces occur. An extreme example is the Babson task, where underpromotions by black are countered by matching underpromotions by white (so if black promotes to a rook, so does white, if black chooses a knight, so does white, and so on) - white's underpromotions are the only way to mate black in the stipulated number of moves.
Underpromotion also features in a number of endgame studies, with the Saavedra position perhaps the most famous example.