Dropping the atomic bombs on Hiroshima and Nagasaki in August of 1945 was ultimately US President Harry Truman's decision. He made this choice for several reasons.
First, the United States insisted that Japan surrender unconditionally. A faction of Japanese leaders had signaled their willingness to surrender earlier in the summer, but made keeping the position of Emperor intact a condition. Though the US eventually allowed Hirohito to remain in the office of Emperor, they declined this condition at the time.
Second, the relentless firebombing campaign against Japanese cities had led to nearly total devastation of cities including Tokyo, but the Japanese leadership, particularly a hard core of military leaders, refused to surrender unconditionally, preferring—at least publicly—to tempt the United States into an invasion. The projected human cost of this invasion was extraordinarily high. Based in part on their analysis of the brutal campaign in Okinawa, where civilians died alongside Japanese soldiers fighting the Americans, planners predicted catastrophically high casualties.
Truman decided that other proposed courses of action, which included exploding a bomb on a deserted area in Japan to showcase its destructive capability would not have the desired effect of frightening the leadership into unconditional surrender. This step had been recommended by many of the scientists responsible for developing the weapon. Over their protests, and the disagreement of some military leaders, Truman ordered the bombing of Hiroshima and then Nagasaki.
Some historians have argued that Truman hoped, by using the atomic bomb, to frighten the Soviets into softening their position on occupying Eastern Europe. It was, in fact, at Potsdam, the highly contentious meeting between the powers in the wake of the European war, that Truman issued a warning to Japan threatening complete devastation if they did not surrender. At the very least, dropping the bombs would mean the United States did not have to depend on the USSR to enter the war against Japan, an eventuality that would have given them more sway in the postwar Pacific.
These motives, of course, are not mutually exclusive. Truman wanted to end the war, and he also almost certainly perceived that doing so with a horrific new weapon—one only possessed at the time by the United States—would carry strategic advantages in the postwar world.