If so, how did it happen and why?
In 1968, Humphrey was the Democratic convention nominee despite not having won a single primary. But there were special circumstances, like the assassination of Robert Kennedy. So, Humphrey didn't "lose" the primaries, in the way I think you are asking.
Could you please clarify, what do you mean lost in the primaries but won at the convention or won the white house? Do you mean in general or in one election cycle? Are you saying lost one of the primaries but still got the nomination, or someone got to the required number of delegates for nomination but someone else was nominated?