I honestly don't think he wanted to be president the first time. It would have made sense for him to make a big show of running, but lose, and just embrace the publicity.
Of course that assumes a level of foresight and planning that he hasn't demonstrated since, so it's hardly a firmly held belief.
Had he lost in 2016, I think he would have been secretly happy about it, but would have publicly griped about "stolen elections" and the like. Then, he would have gotten paid to go on talk shows and give speeches for 4 years about how the Democrats stole the election from him and how he could easily fix every problem facing America (without actually giving a single detail on what he'd do).
I just don't feel that lines up with his behaviour anywhere else.
He has a pathological need to be seen as "best at everything" and will publicly say embarrassing, easily exposed lies.
He claimed he had the biggest inauguration. He claimed to be in incredible physical and mental health. He claimed the head of the boy scouts called to tell him "he gave the greatest speech they'd ever been given".
He took a sharpie to a hurricane map because he knows better than meteorologists. He told people to inject bleach because he knows better than experts in medical science. Butch manly men walk up to him crying tears of gratitude because they love him so much.
The "stolen election" excuse is another of these excuses. He can't admit he lost because only losers lose, so he started a lie that blamed anything except his personal failings.
2016 was not the first time he ran. He had multiple presidential bids in previous election years, most of which amounted to nothing other than free publicity for him and a stroke of his own ego. He was never taken seriously and would always bow out after raking in some donations that he probably embezzled.
Then 2016 happened and suddenly everyone was taking him seriously this time. I really do believe he didn't expect to have a chance at winning against Hillary and that's the only reason he didn't bow out early in the race like he usually did. He was having fun shit-smearing the other Republican candidates live on stage at debates and must have thought nobody would actually vote for him. The look on his face when they announced the winner wasn't the look of someone overjoyed to have been elected President.
He needs to win. The crimes he's committed are obviously crimes, well documented, and he has gone right up to the line on publicly admitting this. The only way he stays out of jail is if he wins and pardons himself. Or if the hamberders block his heart in the next year.