Pearl Harbor was attacked in December 1941, the Manhattan Project was created in 1941, the program was created to secretly built an atomic bomb, it was originally projected against Nazi Germany, but in May 1945 Germany surrendered and the US still had the bomb and still was at war with Japan that did not surrender.
They were four years into the war, the US Army invaded Okinawa and Iwo Jima, yet the Japan military resisted.
In July 1945 the Manhattan project successfully detonated the atomic bomb in a test site in the desert of New Mexico.
There was another element into question: The Soviet Union entered the war against Japan and the atomic bomb would send a strong message to the Soviets. This way, Truman decided to drop the bomb on the city of Hiroshima on August 6th of 1945, three days later another bomb was dropped over Nagasaki.
On August 15th Japan surrendered ending the WWII, and Truman faced heavy criticism. Some argued that Japan was on its knees and the bombs were unnecessary, others pointed to the Soviets as a motive.
The bomb ended WWII but started the long Cold War with the Soviet Union, it lasted 50 years and ended with the fall of the Berlin Wall.