I have heard from many a story in which a man who introduced the game of chess was hanged or killed by his king. What was the actual story and the the reason for killing the founder of chess?
The exact origins of chess are not known, but there are several stories about it out there. At the top of my head I can think of at least four different ones that I've heard myself, and after reading your question I suspect that you've heard of one such story about the creation of chess.
One of these, which may or may not be the story you seem to have learnt about, is the one that follows:
A long time ago, a bored king asked one of his underlings to bring him some form of fresh entertainment. The underling thought for a while, and came up with the game of chess. After playing one game, the king was so pleased with what the underling had brought him that he said that the underling could ask for anything he desired as a reward for the invention of the brilliant game.
After contemplating for a while, the underling asked for a grain of rice for the first square of the chess board, two grains of rice for the second square, four grains for the third square, and so on for the remaining squares. The king agreed to the request, and when it was realized that the total amount of grains the underling had asked for was impossible for the kingdom to provide, the king got angry and ordered the execution of his underling for making a fool out of him.
It is important to note, however, that this story has no proven historical validity whatsoever.
That story seems to be a Hindu legend of the Ambalappuzha Sri Krishna Temple.
Basically the story goes:
The god Krishna, disguised as a sage, appeared in front of a king and challenged him to a game of chess (chaturanga?). The king accepted and asked him what prize he wanted if he won. He said he was a man of few needs so asked for a few grains of rice, the exact number being determined using a chessboard as following: one grain of rice would be placed on the first square, two on the second, and so on doubling the amount each time. The king was unhappy with his request and offered more riches, but he declined.
The game started, and the sage, being a god, obviously won. As the king started to pay the sage's prize, he realized that there wasn't enough rice in his kingdom to pay the prize. The sage transformed back into his god self and told the king the prize didn't have to be payed immediately. He would serve paal-payasam (some sort of food made of rice) to pilgrims every day until the debt was payed off.
In this story, no one dies, and it seems like this is the most correct version, as it's part of Hindu culture.
(There is also more information over at Hinduism SE).
The story you heard might be based on "The Game and Playe of the Chesse" by William Caxton. But there's a difference in that (spoiler)
this story has a happy ending.
The story might be older than Caxton. Caxton's work is based on "Liber de moribus hominum et officiis nobilium super ludo scacchorum" by Jacobus de Cessolis and it might be a translation. I can't say if the story is even older than that. The full text of Caxton's book is online thanks to the University of Rochester and has great footnotes. It's a tough read if you're from this century or one of the recent ones. I'd recommend reading chapter 8 as an overview of the story, but chapter 1-3 also contain a lot framing story.
I'll summarize here:
Once upon a time, Babylon had an evil king named Evylmerodach son of Nebuchadnezzar. A good philosopher named Philemetor saw how evil the king was and decided he had to teach the king about virture. Philemetor knew that the king usually killed people who tried to correct his cruelty, but the philosopher knew that it was so important that everyone do the right thing, especially kings. He knew that even if the king kills him, it is worthwhile to teach him about virtue.
So, the philosopher made a board game and brought it to the king, who insisted on learning how to play this new game. The philosopher taught him all the pieces one by one, how they each correspond to a station in life, and how everyone has to live up to virtues depending on their station in life.
The king demanded he explain himself, and say why he invented this game, or else be killed. The philosopher, knew that the king had a history of killing people who tried to teach him morals, but decided to tell the truth. "To correct you of your tyranny and vicious living. For all kings ought specially to hear their correctors and to keep their corrections in mind."
The king heard this, and thought it was a good correction. He thanked the philosopher, and changed his ways. And they all lived happily ever after.