One popular and influential story of this type is "Godfather Death" (Der Gevatter Tod), a German folk tale collected by the Brothers Grimm, published in 1812. You can read the German text here, an English text here, an annotated English text here. From the Wikipedia synopsis:
A poor man has twelve children, and works just hard enough to feed each of them every day. When his thirteenth child is born, the man decides to find a godfather for this child. He runs out into the highway, and finds God walking on the highway. God asks to be the godfather, promising the child health and happiness. The man, after finding out that the man is God, declines, saying that God condones poverty. Then the man meets the Devil on the highway. The Devil asks to be the godfather, offering the child gold and the world's joys. The man, after finding out that the man is the Devil, declines, saying that the Devil deceives mankind.
The man, still walking down the highway, meets Death. The man decides to make Death the child's godfather saying that Death takes away the rich and the poor, without discrimination. The next Sunday, Death becomes the child's godfather.
When the boy comes of age, Death appears to him and leads him into the woods, where special herbs grow. There, the boy is promised that Death will make him a famous physician. It is explained that, whenever the boy visits an ill person, Death will appear next to the sick person. If Death stands at the persons head, that person is to be given the special herb found in the forest, and cured. But, if Death appears at the persons feet, any treatment on them would be useless as they would soon die.
The boy soon becomes famous, just as Death has foreseen and receives plenty of gold for his amazing ability to see whether a person would live or die. Soon, the King of all the lands becomes ill and sends for the famous physician.
When the physician goes to see the King, he notices immediately that Death is standing at the foot of the bed. The physician feels pity for the king, and decides to trick Death. The physician then turns the King in his bed so that Death stands over the head. He then gives the King the herb to eat. This heals the King and speeds his recovery.
Soon after, Death approaches the physician, expressing his anger for tricking him and disobeying Death's rules. But because the physician is Death's godchild, he does not punish him. Death then warns the physician that if he was to ever trick Death again, he will take the physician's life. [. . .]
A modern (1953) retelling, "The Third Guest" by B. Traven (author of The Treasure of the Sierra Madre), was the subject of this story-identification question.