Usually it's the guy and his gal walking off into a sunset, not the guy and his unethical counterpart strolling into a heavy mist. But if no one ever rewrote the script, we'd never have any new stories, so…
The writers of Casablanca weren't even sure how the movie was going to end, or who would wind up with who, until late in the game. The script was being written and fine-tuned all the way through production (which makes its unqualified success an even more astonishing achievement). The screenwriters tossed around all the possibilities, but finally decided that, for Rick to redeem his soul, he needed to make a huge sacrifice. At the same time, they didn't want our hero to suffer unnecessarily after making such a momentous leap, so they had Renault turn a corner of his own.
And finally, the two on-again-off-again friends get to walk away, nearly hand in hand, in search of a better future. And maybe in search of a breakfast burrito. All that personal growth tends to make a guy hungry.
P.S. The censorship codes at the time wouldn't let the film reward an adulterous relationship. Ilsa had to go off with her husband instead of Rick...or else face blowback from the censors.