I hate to break it to you, but in a close nomination race, it's entirely possible that the voters won't choose the nominee. The veneer of "democracy" is more or less a charade.
In a close race, the only thing that count are the "super delegates"; i.e., democratic members of congress and democratic governors. If the race is super close, the one who racks up the most endorsements of establishment Dems - the super delegates - wins the cookie. In theory, it's entirely possible that one candidate could win the most delegates and the most votes, but the establishment super delegates could throw their weight behind the second place candidate.