The most popular legend attributes the discovery of coffee to Kaldi, a young Ethiopian goatherd, and his goats. According to this tale, one day Kaldi noticed his goats bouncing about the hillsides in a strange manner after they had eaten some red berries from a hillside shrub. So Kaldi, feeling rather tired and troubled, tried eating some of the berries himself. Immediately he began to prance and cavort with his goats, forgetting his troubles and tiredness. From then on Kaldi and his goats cheered themselves each day by eating the red berries.
When the head of a nearby monastery happened to see Kaldi and his goats dancing about, the monk asked for an explanation of the strange behavior; after sampling some of the fruits himself, the monk immediately felt exhilarated. In one version of the legend the monk boiled some of the berries to make a liquid to drink so he and his fellow monks could stay awake during religious services. In another version, Muhammad appeared to the monk later that night as he napped during prayer, and instructed him to boil the red berries in water and drink the resulting liquid in order to stay awake and pray.
Within a short time the news of this magical drink reached all the monasteries in the kingdom. The drink became known as Qahwah, which means "invigorating and stimulating." (Since it is the word for wine, prohibited by Muhammad, the drink eventually was called the Arab's wine.)
In another legend even more closely linked with Islam, the Angel Gabriel comes to Muhammad in a dream and reveals to him the nature of the red berry and its possibilities as a drink to stimulate the prayers of his disciples.
An ancient Arabian chronicle (preserved in the Abd-al-Kadir manuscript), the first existent text to mention the origin of coffee, gives yet another legend relating the discovery of coffee to a follower of Islam, this includes the tradition of roasting the berries and using coffee as a medicine. Known for his ability to cure the sick through prayer, a dervish, named Omar, was exiled from Mocha to a desert cave near Ousab. Starving, he chewed the berries from a nearby shrub; but they were bitter, so he tried roasting them to improve their flavor. When they became hard, he then boiled them in water in an attempt to soften them. Only a fragrant brown liquid resulted, but Omar was so famished that he drank it. The beverage immediately revitalized him and sustained him for many days. Eventually, patients from Mocha came to the cave in Ousab for medical advice from the exiled healer, tried this drink as a medicine, and were cured. When stories of this "miracle drug" reached Mocha, Omar was asked to return and was made a saint.
It seems likely that coffee was first eaten as food in Ethiopia and Arabia too, and only later was boiled with water to make a beverage. It is also possible that in early times a wine was made from the fermented pulp of the ripe berries. Some authorities think this may be the reason why Qahwah (which means both coffee and wine) is the word for coffee. Coffee as a beverage may have started as a wine. Sun dried beans probably inspired the idea of roasting, but exactly how and when the red berries became the beverage we now recognize is a matter of historical conjecture.