It is said that if you are abstaining from drinking alcohol, you are effectively "on the wagon".
The term has been associated with the Salvation Army and their push for temperance, especially during the days of horse drawn wagons in America.
It was said that the Salvation Army would drive their wagon down city streets and call upon drinkers to get on the wagon and off alcohol by getting help with their organization.
However, the actual etymology of the phrase is related to a water wagon of the old days (early 1900’s) that would spray water onto the unpaved roads in order to keep down dust.
Hence, if you were "on the wagon", you were on the "water wagon" and not drinking alcohol.