I don't see how in the days before primaries decided the nominee, a president could have lost.
It happened but not very often.
Iirc the last
elected President to be denied renomination was Franklin Pierce in 1856. However, Presidents who had succeded from the Vice-Presidency were soemtimes rejected - TR was in fact the first such to be nominated for an elected term - so Chester Arthur was rejected in 1884 in favour of Blaine. By contrast, only eight years later Benjamin Harrison was renominated though almost certainly doomed to lose - as Taft would be in 1912 and Hoover in 1932.
As the Federal government grew in scope, the President acquired more patronage, and in the 20C it became increasingly difficult to deny him renomination, no matter how hopeless his prospects for November.