The "first video game" is a debated topic. The idea of a computer that could play games traces back to Charles Babbage himself. While designing his never-completed Analytical Engine in 1837—a machine he hoped could perform any mathematical function—he realized it could play simple games like tic-tac-toe and chess.
The first actual computer to play a game was the Nimatron, built by Edward U. Condon in 1940 to play the Chinese game of Nim. It displayed the game by lighting up columns of bulbs and was shown at the 1940 New York World's Fair, where 50,000 people played it.
Source: https://deserthat.wordpress.com/2010/05/18/earlyer-computer-games-babbage-and-nimatron/
The first computer game shown on an actual screen was OXO, written for the EDSAC computer by Alexander S. Douglas in 1952 for his PhD thesis at the University of Cambridge.
Spacewar!, developed by Steve Russell in 1962, was the first computer game made for an existing system—the PDP-1—and the first to be distributed, with its source code shared freely on request.
Computer Space, made in 1971 by Nutting Associates, was the world's first commercially sold video game. This coin-operated game was created by Nolan Bushnell and Ted Dabney, who later founded Atari.
A year later, in 1972, the Magnavox Odyssey, created by Ralph H. Baer, became the first commercially sold video game console.