Stalemate occurs when the player to move has no legal move and the king is safe. A strong piece can accidentally take away the opponent’s last escape square without giving check.
A position repeated three times can support a draw claim under standard over-the-board rules. The same side must move and the same legal options must exist, including castling and en passant rights. Fivefold repetition is automatic under FIDE rules.
FIDE rules distinguish a 50-move claim from the automatic 75-move draw, measured for each player since the latest pawn move or capture. Checkmate on the last move takes precedence. Dead positions and draw agreements are other cases. Check how your event or app handles claims.
Worked example
With Black’s king on a8, White’s king on c6 and queen on c7, Black to move is stalemated. In the exercise, White can avoid that outcome.