So it's worth acknowledging, first of all, that there is scholarly disagreement on this. There are basically three positions one can take:
First position: "they mattered," because of their novelty and potential. This is the most "basic" position one sees reflected in discussions of the atomic bombs, and perhaps the one that tends to be deployed most naively, inasmuch it is almost totally without reference to the Japanese point of view. The closest one gets to a statement from the Japanese that implies it is Hirohito's "Jewel Voice Broadcast" of surrender from August 15th, which includes one direct reference to the atomic bomb:
Despite the best that has been done by every one -- the gallant fighting of military and naval forces, the diligence and assiduity of Our servants of the State and the devoted service of Our one hundred million people, the war situation has developed not necessarily to Japan's advantage, while the general trends of the world have all turned against her interest. Moreover, the enemy has begun to employ a new and most cruel bomb, the power of which to do damage is indeed incalculable, taking the toll of many innocent lives. Should we continue to fight, it would not only result in an ultimate collapse and obliteration of the Japanese nation, but also it would lead to the total extinction of human civilization. Such being the case, how are We to save the millions of Our subjects; or to atone Ourselves before the hallowed spirits of Our Imperial Ancestors? This is the reason why We have ordered the acceptance of the provisions of the Joint Declaration of the Powers.
Should we take this at face value? Well, we'll come back to that question. But if you're going to make this argument, this is basically all you've got, other than the apparent coincidence of timing (atomic bombs dropped on August 6 and 9th, surrender on August 15th, which is how many textbooks present it, omitting intervening events).
Second position: "they played a role, but were not the only thing that mattered." This position is considerably more supported by contemporary evidence, especially from the Japanese side. To understand the Japanese surrender one needs to understand the state of the war from the Japanese perspective in the summer of 1945. Much can (and has) been said about this, but we might summarize it as follows.
Japan during World War II was being run by a cabinet, over which the Emperor in principle was the overriding voice but in practice he was not meant to intervene in mundane affairs. The cabinet was split between a "war party" and a "peace party." The "war" contingent was a slender majority, made up primarily of military ministers. The "peace" contingent included several bureaucrats and the Emperor himself. While the "war" contingent was at its most rational in favor of a "bleed the Allies out" strategy (they were of the belief that the American public would not tolerate the heavy casualties of an invasion), and at its most irrational in a state of mind that actually thought victory could still be possible, the "peace" contingent was looking for a diplomatic end of the war. Towards this end they were attempting to engage the then-neutral Soviet Union to act as a peace broker to negotiate a surrender agreement. They were not willing to accept the "unconditional surrender" demanded by the United States, however: they believed that at a minimum the position of the Emperor and the Imperial House needed to be preserved in postwar Japan, and at a maximum appeared to at times believe they could get terms that might give them back, or allow them to keep, some of their conquered territories. The US, as an aside, was aware of all of these machinations because they had cracked the Japanese diplomatic codes some time previous, and these played into US calculations about the end of the war.
In this framing, the atomic bomb was meant to be the sort of thing that could convince the Japanese that their position was even more hopeless than they knew it to be, and might "dislodge" the stalement in the Japanese cabinet.
Did it do so? It isn't clear. The atomic bomb was dropped on August 6th. The Japanese high command learned of it from Allied propaganda not long afterwards, and the cabinet met. They agreed to send a scientific team to confirm that the attack on Hiroshima was indeed an atomic bomb (and not just a propaganda bluff). This took some time; the delegation arrived only on the morning of August 8th, and submitted a report back to Tokyo that evening. It confirmed that the bomb was an atomic bomb, that the city had been destroyed by a single weapon.
But on that same day, something else occurred which complicated the situation even further: the Soviet Union declared war on Japan, and at midnight transbaikal time invaded Manchuria, sweeping aside the Japanese forces there. The Japanese high command had not anticipated this at all, and agreed to meet about it the next morning (August 9th).
The Soviet invasion provides an alternative and in many ways compelling candidate to why the Japanese cabinet changed their mind. It dashed two hopes at once. First, it clearly dashed the hope of the "peace" party that they could use the Soviets at neutral intermediaries. But secondly, and importantly, it also terrified the "war" party, who knew that Stalin would not mind trading blood for territory (unlike their stereotypes of a fickle US public), and whose own analyses from years earlier had predicted that Soviet entry into the war would lead to a total military rout (something encouraged by the collapse of their Manchurian forces). And neither party relished the idea of a Japan split into "occupation zones" like Germany.
It was during this meeting that the Nagasaki bombing occurred; it was announced at the meeting but seems to have had little effect on the conversation or positions.
By the end of the meeting the cabinet had agreed to accept a conditional surrender: they would accept the terms of the Potsdam declaration except that they deliberately carved out a space for the Emperor and the Imperial House.
The United States rejected this partial surrender and insisted on unconditional surrender. They also stepped up further conventional bombing. In the meantime, several junior Japanese officers against surrender attempted a coup, but it were put down by senior military officers. Finally, on August 15th, Hirohito himself intervened to accept unconditional surrender.
Even the above, with its detail, is highly abbreviated. But you can see how many complicated factors are involved in the end of the war. So one position, as indicated, is that the atomic bomb (mostly Hiroshima) and the Soviet invasion together compelled the Japanese to surrender when they did. This is ultimately the position of Tsuyoshi Hasegawa in his Racing the Enemy, for example. In this view, the atomic bomb had some psychological effect, but it was the Soviet invasion that was needed for the end of the war to come when it did — that ultimately it was "two shocks" that ended the war.
Thirdly, one can — and a few scholars do — take the position that the atomic bomb did not meaningfully contribute to the end of the war. This position is a more extreme take on the second position: that the Soviet declaration of war and Manchurian invasion by itself was sufficient to end the war, and that the war would have essentially ended even if the atomic bombs had not been used or threatened. This position sees the lack of Japanese urgency after Hiroshima (and apparent non-response to Nagasaki) as evidence that the atomic bomb was not sufficiently compelling by itself, and that it was indeed seen as a mere extension of conventional aerial attacks, which Japan had already suffered in great amounts. This advocates of this position (such as Ward Wilson) also bring up the fact that in no war before nor since has aerial bombardment been sufficient to compel surrender: that if the atomic bombs had indeed brought about surrender, it would be literally the only time in modern history that this had occurred. (Those in favor of the position that the bombs did do this would again point to their novelty as an explanation for this.)
There is a hidden fourth position (which is the one I take) that I call the "agnostic" position, which says, in essence, that not only can we not disentangle the various forces (including the atomic bombs, the Soviet war declaration, the attempted coup, etc.) that led to the end of the war, but that the Japanese probably couldn't either. They all overlap. They all probably played some kind of role in the individual members of the cabinet, to greater and lesser degrees. They all added up to a cabinet that saw no future in the war, and an Emperor willing to take extraordinary action — an action that he believed could have led to his own prosecution as a war criminal (but did not) and the destruction of the Japanese Imperial house (but did not). Trying to disentangle these influences is impossible, and instead of talking about single (or even multiple) forces that "ended the war," we need to paint the situation in at least as complex terms as I've outlined here, pointing out that history is complicated and doesn't boil down to moral or political lessons for the present. But this position generally makes everyone unhappy, because people want the atomic bomb to serve as a moral/political parable: those of the first position use it as a form of "ends justify the means," those of the third position use it as a form of "nuclear weapons are useless and should be banned," and those of the second position are usually just trying to defray the first position, which is so dominant in US culture.
(continued below)