Ah, it's easily missed, but in Matthew 7:24 it says, "Therefore whosoever heareth these sayings of mine, and doeth them, I will liken him unto a wise man, which built his house upon a rock:"John 6:40 - For my Father’s will is that everyone who looks to the Son and believes in him shall have eternal life, and I will raise them up at the last day. Nothing in Matthew 7:21 or John 6:40 about saved by works.
This is at the end of the sermon on the mount, and the sayings Jesus has been preaching are moralistic sayings such as do unto others as they do unto you and judge not that ye be not judged. Since in verse 24 Jesus says he will consider anyone wise who puts his sayings into practice I think one can surmise that the will of the Father includes doing things such as what are included in his sayings (the will of the Father which we must do to enter into the kingdom of heaven, according to Jesus), therefore certain works are necessary for salvation according to Jesus.
Here's the four verses when read together:
21 Not every one that saith unto me, Lord, Lord, shall enter into the kingdom of heaven; but he that doeth the will of my Father which is in heaven.
22 Many will say to me in that day, Lord, Lord, have we not prophesied in thy name? and in thy name have cast out devils? and in thy name done many wonderful works?
23 And then will I profess unto them, I never knew you: depart from me, ye that work iniquity.
24 Therefore whosoever heareth these sayings of mine, and doeth them, I will liken him unto a wise man, which built his house upon a rock: