There were several reasons why the United States decided to use atomic weapons against Japan to end the fighting of World War II. As the question suggests, a major one was to save the lives of American soldiers.
As American forces island-hopped their way towards Japan in 1944 and 1945, it became clear that the Japanese had no intention of surrendering. The Japanese fighting in various recent battles had been fanatical. Their forces never surrendered and fought to the death. The death toll on even small and relatively insignificance islands had been extreme. On Okinawa, one of Japan's southernmost home islands, fighting had been so severe that American casualties were roughly one in three. It became assumed that an invasion of Japan itself would be even more brutal.
It was clear that an invasion force would face whatever remained of the Japanese military as well as a hostile civilian population. It is likely that casualties would have been extremely high, both for Japanese civilians and for American soldiers, sailors, and marines. There were some estimates that placed American casualties from an invasion in the millions. After years of fighting in Europe and the Pacific, the prospect of continuing the bloodshed seemed unfathomable to many Americans.
President Truman took all this into account when he made his fateful decision to use the atomic bombs. He wrote, "My object is to save as many American lives as possible but I also have a human feeling for the women and children of Japan."
Further Reading