Saving American lives was probably the dominant factor, but Americans expected that a land invasion would also kill millions of Japanese, far more than the atomic bombs.
There are strong indications that a surrender would occur regardless and why would the only alternative to a land invasion of Japan be dropping two nuclear bombs on Japanese cities.
They didn't surrender after the first, and the military leadership didn't want to surrender after the second (the emperor did anyway and there was an attempted coup).
Note that more people were killed by firebombing Tokyo than either nuke, Japan was completely at the mercy of US bombing raids before the atomic bombs and they still refused to surrender.