Two things: gravitational contraction, and most importantly, nuclear fusion.
In general, anything that contracts because of gravity heats up. It's sort of like how if you drop a coin into one of those "black hole" things the coin goes really fast due to gravity. Atoms, protons and electrons going fast = hot.
But what really makes the sun shine is nuclear fusion. Gravitational contraction makes a protostar, a hot, dense object. When it becomes hot and dense enough, fusion occurs, and the star is born: protons can hit each other and fuse to form helium nuclei, releasing a lot of energy. (They also combine with neutrons, which can be made from protons and electrons).