Early in this passage, Jesus says that "only he who does the will of my Father who is in heaven" will enter the kingdom. At first glance, His rejection of those claiming to do good works in His name seems contradictory. After all, they are apparently doing things to right the world twisted by sin. However, with a closer look at the means of salvation, the reader can see that it is not contradictory at all.
Romans 3: 10-12 says "There is no one righteous, not even one; there is no one who understands, no one who seeks God. All have turned away, they have together become worthless; there is no one who does good, not even one." This causes us to question what it means to be righteous. We see people all the time helping the poor, feeding the sick, and doing all sorts of kind things for others, and yet the bible calls us all dead in sin (Eph. 2:1). So how do we reconcile this? Our immediate reaction is to believe the bible is contradictory. We all want to agree with Helen Keller in saying that everyone is basically good, because we don't want to believe that everyone is basically evil.
It would help if we first define what it means to do good. Matthew 7: 21 reconciles this. Jesus defines righteousness by saying that only those who do the will of the Father will enter the kingdom. Therefore, only good works that are specifically God's will are actually good works. Isaiah 64:6 says that 'our righteous acts are like filthy rags'. So who can enter the kingdom?
Only one man ever did the will of the Father. Philippians 2: 5-11 tells us of Christ doing the will of the Father, and He was therefore glorified. Only Christ can enter the Kingdom of Heaven on His own works, his own merit.
So how on earth can we enter the kingdom? Matthew 7:24-27 clears this up. We must build our lives on Christ, put our faith in His works and merit and not our own. Thankfully we do not have to initiate this. Eph. 2:8-9 says that grace saves us.
So I end my rather discombobulated argument with Paul's praise: "Thanks be to God - through Jesus Christ our Lord!"