The best way to think of how bonding works respective to different elements is the amount of bonds they tend to form. The general rule is that carbon will have 4 covalent bonds, nitrogen will have three covalent bonds, oxygen will have two covalent bonds and hydrogen will have just one. From that mechanism, you can see the intermediate species has an oxygen that's bonded only once, and therefore has a lone pair (electrons not used in the covalent bonding) which it will transfer to the hydrogen ion to form a second covalent bond.