North Korea conducted a sixth nuclear test at the weekend, saying it was a hydrogen bomb that could be fitted onto a missile.
"Why has North Korea chosen this path today which has worried people in East Asia? It is because of threats against North Korea's existence," Rouhani said in a speech to his cabinet shown on state television.
"Can one joke around with atomic weapons? When a country has obtained an atomic weapon, then the game of threatening them becomes a dangerous game for the entire world," he added.
"We believe this issue must be resolved through negotiations and dialogue."
North Korea conducted a sixth nuclear test at the weekend, saying it was a hydrogen bomb that could be fitted onto a missile, prompting the US to accuse the isolated nation of "begging for war".
Rouhani said US officials needed to tone down their rhetoric.
"Leave them be. Don't threaten North Korea so much, and she will pursue her life and that of her people," he said.