Then He will also say to those on the left hand, "Depart from Me, you cursed, into the everlasting fire prepared for the devil and his angels: for I was hungry and you gave Me no food; I was thirsty and you gave Me no drink; I was...naked and you did not clothe Me..." Then they also will answer Him, saying, "Lord, when did we see You hungry or thirsty or a stranger or naked or sick or in prison, and did not minister to You?" Then He will answer them, saying, "Assuredly, I say to you, inasmuch as you did not do it to one of the least of these, you did not do it to Me." Matt. 25:41-45, NKJV.
In the overall context of the parable of the sheep and the goats, it is the Pharisees and their kind who are lost because they did not understand true religion. They had an outward form in doctrine, lifestyle, and religious ritual, but it hadn't entered their heart and made them more loving. Doctrine, lifestyle, and ritual are not ends in themselves, but rather a means to experiencing a transformed heart that leads to a life of loving and caring. Without the end product, those things that so-called religious, churchly people regard as important have no value. And those who focus on the wrong "religious" activities will be lost according to Jesus.
Ellen White sums up the teaching of Jesus nicely. Commenting on the parable of the sheep and the goats, she writes that Jesus "pictured to His disciples the scene of the great judgment day. And He represented its decision as turning upon one point. When the nations are gathered before Him, there will be but two classes, and their eternal destiny will be determined by what they have done or have neglected to do for Him in the person of the poor and the suffering" (The Desire of Ages, p. 637).
That is not salvation by works, but rather a heart response to the love of God--an internalization of that love that passes on to others His gifts to us. An important lesson of the parable is that the activities that really count are simple and uncalculating.
It is the unconscious internalization of God's love and its expression in daily life that is the one essential qualification for the kingdom of heaven. Such people have begun to live the principle of servanthood and greatness that has come up again and again in Jesus' teaching. They are safe to save for eternity, because they have internalized the principle of love, the principle of the kingdom. As a result, they have developed through grace that "righteousness [which] surpasses that of the Pharisees and the teachers of the law." Thus they are prepared to "enter the kingdom of heaven" (Matt. 5:20, NIV).
Father, help me to be one of those people.