UNITED NATIONS — President Obama on Tuesday used his last major address on a global stage before the November election to deliver a strong defense of America’s belief in freedom of speech, challenging fledgling Arab and North African democracies to ensure that right even in the face of violence.

The speech was in many ways a balancing act for Mr. Obama, who has had to contend with angry anti-American demonstrations throughout the Middle East during the past several weeks, and a Republican opponent, Mitt Romney, who says the president has projected weakness in his foreign policy. Mr. Romney has criticized the administration for issuing what he called “an apology for American values” in its initial response to the demonstrations.

Mr. Obama’s message seemed intended to appeal to a domestic audience as much as to the world leaders at the General Assembly.

In a 30-minute address, he affirmed what he said “are not simply American values or Western values — they are universal values.” He vowed to protect the enduring ability of Americans to say what they think. He promised that the United States “will do what we must to prevent Iran from obtaining a nuclear weapon.” And he asserted that the flare-up of violence over a video that ridicules the Prophet Muhammad would not set off a retreat from his support of the Arab democracy movement.