When trying to solve thorny political questions like this, it can be helpful to construct simpler examples and see if they give any help.
If a genuine US citizen stood as a presidential candidate, and ran a winning campaign, but was replaced on election night by an impersonator who wasn't exposed for several weeks, then it's clear that the US citizen is the rightful president and should take office, possibly after some time to recover from their kidnap and imprisonment.
If a genuine US citizen was replaced as a small child by an impersonator, who runs for president decades later and wins, then it's pretty clear that the US citizen is not president, the impersonator is, apart from any problems with eligibility.
For the case in this question, where the replacement was a few years before the election, all of the things done to secure ballot access in the US states for the impostor would seem to have been fraudulent. This makes it hard to count votes for them as valid. Since the opposing presidential candidate will thereby have a large majority of the valid votes, and thus of the Electoral College, they would seem to win more or less automatically.
However, this may well be seen as unfair to all the voters who supported the impersonator, and also opens up a new style of electoral dirty tricks, as the parties try to find ways to invalidate each others' ballot access. So it isn't a very good solution. If it were adopted, the opposing candidate could look very statesmanlike by suggesting that the Contingent Election process would provide a way for it to be settled.
Another way would be to use the Presidential Line of Succession. The problem with that is that most of the people in that line got there by means of action by the impersonator, if they had time to appoint a cabinet. Presidential candidates also have significant influence in the choice of vice-presidential candidates, so the VP is also compromised.
It's a constitutional crisis, and the precise circumstances and timing are likely to determine the outcome, in ways that can't be predicted.