He remitted all the debts that were due to him, and gave public notice that all his debtors had only to come and take back their bonds. They all came and did so. Then he gave away all the wealth he had been amassing for years, till he had nothing left. He built a hermitage on the banks of the Euphrates, where he gave himself up to a devotional life, spending whole nights in prayer. During the day he attended the instructions of Hasan Basri. At the commencement of his religious life he received the appellation "Ajami" (ill-instructed) because he could not pronounce the words of the Koran properly.

After some time his wife began to complain, saying, "I must really have some money; we have neither food to eat nor clothes to wear." At this time Habib was in the habit of going every day to his hermitage on the banks of the river, and spending the day in devotional exercises. In the evenings he came home. One evening his wife asked him where he had been during the day. "I have been working," he replied. "Very well, where are your wages?" she asked. "My employer," said Habib, "is a generous person. He has promised to pay me at the end of ten days." So he continued spending his time as before. On the tenth day, as he reflected in his hermitage, he wondered what he should say to his wife when he returned in the evening, and she wanted something to eat. That day four men came to the house of Habib. One brought a quantity of flour, another a sheep, a third a jar of honey, and the fourth a bottle of oil. Not long after them a fifth came with a purse of gold. They gave all these to Habib's wife, saying to her, "Your husband's Employer has sent these," and they added, "Tell your husband that his Master bids him continue his work, and He will continue his wages." Then they departed.

In the evening Habib came home, pensive and anxious. As he entered the house an odour of cooking greeted him. His wife hastened to meet him, and said, "O Habib, go on working for your employer, for he is very generous, and has sent all that you see here, with this message that you are to go on working, and he will continue to pay you." Hearing this, Habib became more confirmed than ever in his resolve to give up the world and to live to God.

One day Hasan Basri paid Habib a visit in his hermitage. The latter had two barley loaves and a little salt, which he placed before his guest. Just as the latter was commencing to eat and in the act of stretching out his hand, a dervish appeared at the door and asked for alms. Habib immediately handed him the two loaves. Hasan, somewhat ruffled, said, "Habib, you are a good man, but you would be none the worse for a little culture and intelligence. Don't you know that one ought never to take food away from before a guest? At any rate, you might have given one of those loaves to the dervish, and left the other." Habib made no reply. Some minutes afterwards a man came carrying in a napkin a roast lamb, a large plate of sweetmeats, and some money. He set them before Habib and said, "Sir, so and so sends you these with his compliments." Habib and Hasan made a hearty meal, and Habib distributed the money to some passing mendicants. Then he said to Hasan Basri, "My master, you are a good man, but it would have been better had you shown more sincerity in this matter, for then you would have possessed both knowledge and sincerity, and the two go well together."

On another occasion Hasan Basri arrived at Habib's hermitage just as the latter was commencing his evening prayers. Hearing him pronounce the words "al hamdu[32]" as "al hemdu," Hasan said to himself, "This man cannot pronounce the words of the Koran properly; it is impossible to pray with him," and he said his prayers apart. That same night he saw the Lord in a dream, and asked him, "Lord, what must I do to gain Thy approval." An answer came, "O Hasan, thou hadst gained it, but didst not appreciate its value. Thou shouldest have prayed with Habib Ajami. Such a prayer would have had more worth than all those which thou hast made in the course of thy life. The tongues of others may speak rightly, but the heart of Habib feels rightly."

One day Hasan Basri, flying from the agents of Hejjaj ibn Yusuf, the bloodthirsty governor of Irak, took refuge in Habib's hermitage. The pursuers, arriving, asked Habib whether Hasan had passed that way. "No," he said, "he is here in my dwelling." They entered, and seeing no one said to Habib, "O Habib, whatever treatment Hejjaj deals out to you, you will have richly deserved it. Why did you lie to us?" "I tell you," said Habib, "Hasan is within this dwelling; if you don't see him, what can I do?" They again made a search, but not succeeding in finding Hasan, departed. Hasan then came out of his hiding-place, and said, "O Habib, is this the way thou repayest thy debt to thy master, by betraying him?" "Master," answered Habib, "it is thanks to my truthfulness that thou hast escaped. If I had told a lie we should have both been caught." Hasan then said, "What words didst thou recite as a safeguard?" "I repeated ten times," said Habib, "the 'Verse of the throne,'[33] ten times 'Believe in the Apostle,'[34] six times 'Say, there is one God,' and in addition I said, 'Lord, I entrust Hasan to Thee; take care of him.'"

Hasan then asked Habib how he had arrived at such a high degree of sanctity. "I spend my time," he said, "in purifying my heart, while you spend yours in blackening paper" (Hasan having written many theological works). "Alas!" said Hasan. "Must then my knowledge benefit others, only while I have nothing but the outward show of it?"

"We must not suppose," says Fariduddin Attar in narrating the above incident, "that Habib had really attained a higher degree of piety than Hasan; for in the eyes of the Lord nothing is higher than knowledge. The doctors of Islam have said truly, 'In the spiritual path the gift of performing miracles is the fourteenth stage, while knowledge is the eighteenth. The gift of miracles is the reward of many works of piety, while the knowledge of mysteries is revealed only to profound meditation. Consider the case of Solomon, upon whom be peace! He understood the language of birds, and yet, though arrived at such a high degree of knowledge, he submitted to the Law given by Moses, and acted according to its instructions.'"

Every time that he heard the Koran read, Habib used to weep bitterly. Some one said to him, "You are a barbarian (the literal meaning of the word 'Ajami'). The Koran is in Arabic, and you don't understand it; why then do you weep?" "It is true," he said "my tongue is barbarian, but my heart is Arab."