Humans have always been social creatures and in need of friends and companions. A good part of our lives is spent in interaction with others. For Muslims like us who are living in a society where we are clearly a minority, the issue of choosing the right companions is essential for preserving our Deen. Befriending righteous and virtuous Muslims is a necessary means for staying on the Straight Path.
In an authentic Hadith, the Prophet Muhammad (peace be upon him) said: "A person is likely to follow the faith of his friend, so look whom you befriend." [reported by Abu Dawood & Tirmidhee]. Mixing with followers of any way other than that of the Guidance results in a change in one's behaviour, morals and conduct. If we accompany such friends, then we inherit their habits, behaviour and perhaps even their religion. Such a Muslim would find himself in a situation where he is willing to hide his or her Islam in front of those who despise it (those whom he considers as friends) and to separate from the believers. When this situation occurs, a point is reached when there is a very slight difference between the Muslim and his wrong-doing companion. Many times a Muslim is encouraged by his friends to do evil and to forget his duties. The result is that Muslims themselves are often ashamed to leave them to perform prayer, their friends thus causing them to clearly deviate from the Right Path.
Instead of making friends with the misguided ones we should befriend the righteous but still treat everyone else in a gracious and just manner.
In another Hadith, Prophet Muhammad (peace be upon him) said: "The example of a good companion and a bad companion is like that of the seller of musk, and the one who blows the blacksmith's bellows (respectively). So as for the seller of musk then either he will grant you some, or you buy some from him, or at least you enjoy a pleasant smell from him. As for the one who blows the blacksmith's bellows then either he will burn your clothes or you will get an offensive smell from him." [Bukhari & Muslim]
In his commentary of this Hadith, Imam an-Nawawi said that the Prophet (peace be upon him) compared a good companion to a seller of musk and spoke of the virtue of having companions who are good, who have noble manners, piety, knowledge and good culture. Such are those who grant us from their virtue. And he (peace be upon him) forbade us to sit with those who do evil, commit a lot of sins and other bad deeds, as well as with innovators, backbiters, and so forth. Another scholar said: "Keeping good company with the pious results in attainment of beneficial knowledge, noble manners and righteous actions, whereas keeping company with the wicked prevents all of that."
Allah the Exalted says in the Qur'an: "And (remember) the Day when the wrong-doer will bite his hands and say: Woe to me! Would that I had taken a path with the Messenger. Woe to me! If only I had not taken so- and-so as a friend! He has led me astray from this Reminder (the Qur'an) after it had come to me." [25:27-29]. He also says: "Friends on that Day will be enemies one to another, except al-Muttaqoon (i.e. those who have Taqwah)." [43:67]
In two authentic narrations of the Prophet (peace be upon him) we were commanded to keep company with a believer only, and told that a person will be with those he loves. So if we love and associate ourselves with those who are misguided, we should fear for our fate. The wise person is the one who prepares himself for the Hereafter, not the one who neglects his faith and falls into the trap of Satan who tells him that he will be forgiven and that he can do whatever he wishes. If we truly believe that the best speech is the Speech of Allah and that the best guidance is the guidance of Prophet Muhammad (peace be upon him), we should act in accordance with them, lest we build a proof against ourselves. From another perspective, a "believer is the mirror of his brother," and if he sees any faults in the other believer, he draws his attention to it in an acceptable manner, helps him to give it up and to wipe away any evil that he may have.
We ask Allah to make us of the righteous ones and give us companions who will take us away from His wrath and lead us to His pleasure and Paradise.