When your king is boxed in, a rook sacrifice with check may force stalemate or an immediate draw. Always check whether the enemy must capture.
Black looks lost. White's king on f7 and pawn on g6 have taken every square from the black king on h8, and White threatens Rb8 or g7+ with mate to follow. But the very fact that the black king has no moves is the resource.