In the customErrors
node you can set the following attribute:
redirectMode="ResponseRewrite"
This will prevent the page from redirecting and will instead write the error page instead of the one requested.
NB: You will also have to ensure that the page being used as the 404 error page actually itself returns a 404 status code in codebehind; the MS rewrite support doesn't automatically pass the status code through, see link: