According to Roman folklore depiction, Androcles (Androclus in Latin), was a man who is known for befriending a  Barbary lion (regionally extinct).

The story of Androcles reappeared in the Middle Ages as "The Shepherd and the Lion". Later it was too ascribed in Aesop's Fables. This tale of gratitude can be compared to Aesop's other creation, "The Lion and the Mouse" by its moral of the reciprocal nature of mercy. 

The story goes like this :

Roman institution of slavery began with the legendary founder Romulus who gave Roman fathers the right to sell their own children into slavery. This slavery system kept growing with the expansion of the Roman state.

By the 1st-century, slavery in ancient Rome was playing an important role in society and the economy. Slaves from different parts were being purchased and sold. Many slaves for the Roman market were former enemy soldiers acquired through warfare who were either brought back as war booty or sold to traders. There were cases of children of poor roman people who were being sold to richer neighbors as slaves in times of hardship.

Besides manual labor, the slaves performed many domestic services and were employed at highly skilled jobs and professions. Even the accountants and physicians were often slaves. Slaves of Greek origin in particular often were highly educated. Unskilled slaves, or those sentenced to slavery as punishment, were working on farms, in mines, and at mills. Sometimes it was up to the masters if they want any of their slaves to be free, which they did very often with roman slaves. The freed slaves allowed to have a common life.

But after, during the Pax Romana (Roman Peace) of the early Roman Empire (1st to 2nd centuries AD), the emphasis was placed on maintaining stability. Hence the lack of new territorial conquests blocked this supply line of human trafficking. Because of the short supply of new slaves, the existing slaves had to bear too much work burden. 

Now slaves started to be considered as property under Roman law and they lost legal personhood. Most slaves would never be freed. Unlike Roman slaves, the outsiders were now started being subjected to corporal punishment, torture, sexual exploitation (most of the prostitutes were often slaves). They were tortured and traumatized. Hence slaves started to escape from the grasp of their masters. So to maintain an enslaved workforce, legal restrictions were increased on freeing/escaped slaves. The masters stopped freeing their slaves and the escaped ones being hunted down and recaptured either for punishments or reinstallment. 

During this time a non-roman slave named Androcles ran away from his master who was a former Roman consul administering a part of Africa, by whom Androcles had been most cruelly treated. In order to avoid capture, he took himself into the desert. He wandered there for a long time until he was weary with hunger and despair. Just then he found a cave, in which he entered and found it to be unoccupied. He took shelter in it, which turns out to be the den of a lion. Almost immediately, the lion appeared before the horrified wretched fugitive.  

Poor Androcles had no strength to rise and run away. So he gave himself up for the final loss. But, to his utter astonishment, that great beast instead of attacking, came up to Androcles by lifting its right paw and kept groaning. Androcles saw that the lion's paw was covered with blood and much swollen. After observing it more closely, he found a large thorn embedded in the paw, which was the cause of the lion's trouble.

Androcles seized hold of the thorn and drew it out slowly of the lion's wounded paw. The beast roared with pain when the thorn came out. Androcles dressed the wound as well as he could. Soon after the lion found such relief from it that he fawned upon Androcles and licked him out of gratitude. The lion went inside and brought him a young deer that he had slain. Androcles managed to make a meal from it. 

In course of time, the lion's wound healed up completely. The wild beast's gratitude was unbounded. It looked upon the man as his friend, and they shared the cave for some time together and Androcles became quite fond of the huge beast.

After three years, Androcles craves a return to civilization to his fellow-men. He implored farewell to the lion and returned to his town. But he was recognized and soon imprisoned as a fugitive slave. His former master resolved to make an example of him. Androcles was sent to Rome and brought before the authorities. There he was condemned to be devoured by wild animals in the Circus Maximus public spectacle in the presence of an emperor Gaius Caesar.

On the day of execution, Androcles was led forth into the arena. The Emperor in the royal box up above the arena gave the signal to unleash the beasts. Holding their breath the spectators were watching this bloody conclusion. 

The gates opened and a group of lions was loosened into. Among the rest, there was a lion of huge bulk and ferocious aspect. It rushed towards Androcles. But what was the amazement of the spectators, when the furious lion after one glance bounded up to Androcles and lay down at his feet with every expression of affection and made no attempt to do him any harm! Yes, it was Androcles's old friend from the cave! 

The audience clamored and claimed to spare the slave's life. The Emperor was surprised at seeing such strange behavior in a cruel beast. He summoned Androcles to him and asked him why this particular lion had lost all its cruelty of disposition. Androcles told the Emperor all that had happened and why the lion was showing this tamed behavior. Thereupon the Emperor marveling at such gratitude and fidelity in a beast, pardoned Androcles and ordered his master to set him free. Later the lion was taken back into the forest and let loose to enjoy liberty once more.

The tale ends here.

The earliest account of this episode is found in Aulus Gellius's second century Attic Nights.  There the author mentioned a story, told by Apion in his work Aegyptiacorum (Wonders of Egypt). Apion described the events which he claimed to have been a spectator on this occasion.

Apion quoted this incident as -

"Afterward, we saw, Androcles with the lion which was attached to a slender leash, making the rounds throughout the city. Coins were tossed on Androcles and flowers were sprinkled on the lion. Everyone who met them anywhere exclaimed saying, "This is the lion, a man's friend; this is the man, a lion's doctor."

A century later this story was repeated again by Claudius Aelianus in his work On the Nature of Animals which is still delightful to read.