The Japanese leadership did not see the atomics as significantly worse than what they had already suffered due to the sustained bombings their cities had endured in which many more civilians died than from both the bombs combined. What did it for them was the Soviet Union declaring war on them and rapidly taking Manchuria and able to invade via the relatively undefended north and western borders in very short order, like one or two weeks time instead of the months it would take the Americans to get on with it.
There was no point to a valiant stand against the Americans, they would be slaughtered by the Soviets from the other end. At this point they surrendered and to save face, in a way, they attributed their defeat to the magic bomb against which there was no honor in facing.
The US knew this of course, that neither invasion nor the abomb were necessary to end the war because the Soviets would take care of it, but then it was about who got to dictate the terms of surrender and keeping Japan's resources and conquered territories out of Soviet hands. Not an unreasonable motive, which is hard to say when 150-200 thousand civilians died by the bombs, but many more than that would have died by a Soviet invasion or an American one or both. Some in Hirohito's inner circle wanted to bring it to that, fight till the last man woman and child.
Also, the bombs were punitive. I'm not saying this to express approval or disapproval of this, but after all - it is these civilians who sent their sons to massacre the Chinese, taught them that they were the master race to rule the world, commit atrocities, etc. Nanking, Unit 731 (thought Auschwitz was the worst place you could possibly imagine?), etc etc etc
Lastly, just as the Japanese were able to have a "neat" reason to surrender, the Americans wanted a big final bang to symbolize victory and to take their place as the world's #1 superpower, knowing the Soviet Union was going to be competing with them for that claim.