Because the Nazis were making a nuke as well and America managed to beat them just as Nazi Germany fell and also with the help of Albert Einstein.
Japan was still at war with the US and Russia. And the US was scared that Russia will spread communism all over the world after they had taken a lot of territory from the Nazis and plan to do that with Japan (because Japan had controlled resourceful areas in Asia). So the US dropped the first nuke as a show of force towards the Russians and to get Japan to surrender after the US had pretty much annihilated the Japanese Navy and Airforce and leaving their army in shambles. Japan, of course, did not surrender because the Emperor did not declare any sort of surrender (and America didn't target him because the people of Japan saw the Emperor as a God and if he died, they would pretty much create a mass suicide).
So America (I believe either made or had another bomb) dropped another, which finally forced Japan to surrender after the devastation of the two destroyed cities and the mass casualties and wounded. As well as the radiation and the possibility of a all out invasion of the American military (This fear was introduced BEFORE the nukes).