In verses 4-11 of chapter 12 of the New Testament book of 1 Corinthians entitled Concerning Spiritual Gifts, St. Paul the Apostle writes about the different spiritual gifts given to individuals by the Holy Spirit including the spiritual gift of distinguishing between spirits:
4 There are different kinds of gifts, but the same Spirit distributes them.
5 There are different kinds of service, but the same Lord.
6 There are different kinds of working, but in all of them and in everyone it is the same God at work.
7 Now to each one the manifestation of the Spirit is given for the common good.
8 To one there is given through the Spirit a message of wisdom, to another a message of knowledge by means of the same Spirit,
9 to another faith by the same Spirit, to another gifts of healing by that one Spirit,
10 to another miraculous powers, to another prophecy, to another distinguishing between spirits, to another speaking in different kinds of tongues, and to still another the interpretation of tongues.
11 All these are the work of one and the same Spirit, and he distributes them to each one, just as he determines.
New International Version (NIV)