When a king is under attack and threatened with capture by an opponent's piece, the king is said to be “in check”. A king must get out of check immediately. There are three possible ways to get out of check.
Capture the attacking piece.
Move the king away from the attack and to a safe square which is not under attack by an opponent's piece.
Block the attack by placing a piece between the attacker and the king. (Cannot be done for an attack by a knight or pawn.)
If the king has no way to escape from the check, the position is called “checkmate” and the game ends. The player who is checkmated loses the game. The king is never actually captured and removed from the board.
At any time during the game, a player may resign (quit). The game ends and the player's opponent wins the game.
A “draw” is a tie between the players. There are several ways that a draw can occur.
Stalemate - (see below)
Threefold repetition - If the exact same position is repeated at least 3 times (not necessarily by a repetition of moves). It requires that the possible moves of all the pieces of both players are the same. If the possibility of a pawn being captured en passant has changed or the possibility to castle has changed, the position is not the same - even if the pieces are in the same locations.
Fifty-move rule - If no piece has been captured or a pawn moved in the last fifty moves by each player.
Impossibility of checkmate - If a position arises in which neither player could possibly give checkmate by a series of legal moves. Usually this is because there is insufficient material left to checkmate, but it is possible in other positions. Combinations with insufficient material to checkmate are:
king versus king
king and bishop versus king
king and knight versus king
king and bishop versus king and bishop with both bishops on the same color
Time expires - If a player's time runs out and their opponent does not have mating material. (see below)
Mutual agreement - If both players agree to draw.
If a player has no legal move (every possible move would put their king in check) but their king is not presently in check, the game ends in a “stalemate”. Stalemate results in the game being a draw.
If time should run out on a player before they complete the required number of moves:
The player loses the game if the opponent has mating material.
The game is a draw if the opponent does not having mating material.
Mating material is considered to be any group of pieces except just a king, a king and a bishop, or a king and a knight.