Compare Did You Just Scam Cthulhu? for when you cheat death in this game (which may be the origin of the idiomatic phrase). Sub-Trope of Hanging Up on the Grim Reaper. But it doesn't have to be chess-if the player is allowed to pick the game, absolutely anything can happen.
See also Enemies with Death and Smart People Play Chess. The most mimicked version is to have a dying man challenge The Grim Reaper to a chess game in return for a longer life, hence the trope title. Note that the Greek Gods were prone to throwing tantrums if they were beaten and cursing the mortals for it having the supernatural entity take a defeat on the chin was a rarity. This is Older Than Feudalism, with examples dating back to Greek myths of the 5th century BC-Apollo had at least one musical duel, the Muses had another musical contest, and Athena had a weaving contest with Arachne (the details vary between different versions, but the end result is that Arachne is turned into a spider). A character gets into a contest of some sort with The Grim Reaper, Satan, or some other supernatural entity, usually with some dire consequence if the human loses.