The great English theologian John Owen (1616-1683) wrote:

Men may be really saved by that grace which doctrinally they do deny; and they may be justified by the imputation of that righteousness which in opinion they deny to be imputed. —The Doctrine of Justification by Faith Alone, in Owen’s Works 5:163-64.

In some ways Owen’s position is a dangerous one to hold—given the strong connection in Scripture between sound doctrine and assurance—but it’s nevertheless an important principle. Note that Owen doesn’t say that they necessarily are saved but that they may be saved.

I also agree with the qualifier John Piper adds: “The clearer the knowledge of the truth and the more deep the denial, the less assurance one can have that the God of truth will save him. Owen’s words are not meant to make us cavalier about the content of the gospel, but to hold out hope that men’s hearts are often better than their heads” (The Future of Justification, p. 25 n. 30).

Jonathan Edwards (1703-1758) offers a similar statement to Owen’s but goes into greater detail with various options regarding the denial—emphasizing how dangerous false teaching is but also hoping that such a person may be teachable when confronted with his error: