Churchill had warned Roosevelt that the Germans were attempting to build an atomic bomb that could destroy a city with one bomb. Roosevelt ordered the Manhattan project be started as he realised America and the allies must have this bomb before the Germans or the Japanese could perfect one and destroy the allies with them.
The Germans never got near developing the Atomic bomb as British trained Norwegian commandos had successfully destroyed all Germany's heavy water needed for the German atomic experiments, and Hitler had decided it was going to take too long to develop this bomb so basically cancelled the project preferring more conventional proven weapons. The Americans did not explode their first Atom bomb until a few weeks after Germany surrendered.
Japan was still refusing to surrender and had been forced back onto their homeland and was training their people including their school children how to fight with sharpened bamboo sticks as they had no guns to give them. The Japanese were notorious for fighting to the death and never surrendering and the Americans knew they would likely lose a million men in the battle to defeat Japan and knew likely they would have to virtually kill all the Japanese before the war was won. Millions would have died in the invasion and suddenly America had a working Atom bomb they could use hopefully making the Japanese see the futility of continuing to fight. The scientists realised what a destructive weapon they had made and begged President Truman not to use it on a city but to invite the Japanese to a demonstration of the bomb's abilities hoping to scare Japan into surrender. Truman considered all possibilities and worried if the bomb did not work the Japanese would be even more determined to fight on. So it was decided that a city would have to be bombed with one of these new bombs and this was likely pushed by the American military who wanted to see one of these bombs in action to see how good they were, and if as good as they had been believed to be whether it would stop the war with the sacrifice of one city instead of the expected bloodbath and deaths of millions of people right across Japan.
So August 6th Hiroshima was the target and was a direct hit, Apparently the blast cut all communications with the rest of Japan and a plane was sent to see why Hiroshima was not responding by phone or radio calls. At first the Japanese leaders believed it was just a massive conventional bombing raid and refused to believe one bomb could do such damage, so 3 days later the city of Kokura was to be the next target but luckily for them it was cloudy and the air crew could not find the target accurately and the plane crew decided to go to the secondary target of Nagasaki. The Bomb was off target but still did huge damage to the city. By now there was no doubt the Americans had such a deadly bomb so Japan had to consider surrender. Apparently it was not just the threat of these bombs, but also Russia had declared war on Japan about 3 weeks before and had already taken Japanese homeland islands at the northern end of Japan as Japan had been preparing for an invasion from the Pacific and had no real military forces on these islands not expecting Russia to attack. Russia seeing the vulnerability of Northern Japanese islands decided to grab more territory for Russia before the war ended so took advantage of the Japanese situation, and even now nearly 80 years later still refuses to give these islands back to Japan. The Emperor of Japan saw the futility of trying to fight on and ordered the Japanese forces to surrender but some Japanese military leaders who believed it dishonourable to surrender tried to capture the Emperor to force him to order the people to fight on but their attempt failed and Japan accepted its fate as a conquered country. Little did the Emperor know the Americans only had one more atomic bomb and would have taken several months to enrich enough uranium to build any more.
The use of the Atomic bombs were seen as a way to save millions of lives compared to the 200,000 who lost their lives in the bombings. The decision was not taken lightly as Truman did not like the idea of a bomb that was so destructive being used and knew it opened up shocking ideas of what could happen in the future when other countries had such a weapon and would use it in the next world war. The military wanted to see the damage such a weapon could do so were pushing for the dropping of the bomb on a real city, and as soon as the war had ended sent in scientists to gather as much information on the damage inflicted on the city as well as on the people.
One other good thing the Bomb did was prevent the execution of all POWs in Japanese hands. The order had been given that all POWS were to be killed on September 1st 1945 as the Japanese feared they could join the fight with the allies, as well as take soldiers away from the invasion who could be used to hopefully repel the invasion to guard them. The POWS were only 3 weeks from all being murdered.