WASHINGTON — US President Barack Obama promised to keep Iran from obtaining a nuclear bomb and to “stand steadfast” with Israel in his State of the Union speech. He also announced plans to withdraw more troops from Afghanistan and take steps to boost the rocky US economy as he delivered a closely watched address Tuesday laying out his priorities for the year ahead and for his newly begun second term in office.

The speech before a joint session of Congress’ two chambers was dominated by domestic issues, as Obama challenged deeply divided lawmakers to find compromises that would boost job creation and strengthen America’s middle class.

But foreign policy priorities interjected in the hours before the speech, with North Korea announcing that it had detonated a nuclear device Tuesday. Obama said that “provocations,” like the nuclear test, will further isolate North Korea, “as we stand by our allies, strengthen our own missile defense, and lead the world in taking firm action in response to these threats.”

“Likewise, the leaders of Iran must recognize that now is the time for a diplomatic solution, because a coalition stands united in demanding that they meet their obligations, and we will do what is necessary to prevent them from getting a nuclear weapon,” said the president, leaving out last year’s assertion that all options in response to the Islamic Republic’s race for nuclear weapons were “on the table.”

Addressing Middle East issues, near the end of his speech, Obama said America “will stand with citizens as they demand their universal rights, and support stable transitions to democracy. The process will be messy, and we cannot presume to dictate the course of change in countries like Egypt; but we can – and will – insist on respect for the fundamental rights of all people. We will keep the pressure on a Syrian regime that has murdered its own people, and support opposition leaders that respect the rights of every Syrian.”

Touching briefly on Israel and his anticipated visit here, Obama said the US “will stand steadfast with Israel in pursuit of security and a lasting peace.” The statement earned him a standing ovation from the supportive legislators.

Obama also announced that the US will begin talks with the European Union on a trans-Atlantic trade agreement, “because trade that is free and fair across the Atlantic supports millions of good-paying American jobs.”

The annual address is one of the biggest events in Washington. It is broadcast during prime evening viewing hours by the major television networks, with Washington’s most powerful officials — lawmakers, Supreme Court justices, military leaders and Cabinet members — all in attendance and millions of Americans watching from home.

This year’s speech came at one of the strongest points in Obama’s presidency. He won re-election by a convincing margin, is generally popular, and opposition Republicans appear weakened and fractured. Still, Republicans control the House of Representatives and tough fights loom on the budget and other top issues.

In his speech, Obama pressed a theme central to his campaign: that government needs to ensure that every American, regardless of background, has an opportunity to succeed. He called it “the basic bargain that built this country.”

“It is our unfinished task to make sure that this government works on behalf of the many and not just the few,” he said.

With the economy still the biggest concern of most Americans, Obama devoted less time to foreign policy this year. But his announcement on the withdrawal of 34,000 troops from Afghanistan — about half the force there — is a major development, even if it was highly anticipated. It puts the United States on pace to formally finish the protracted war by the end of 2014.

Obama also used the address to press for congressional action on climate change and for stricter gun control laws, both of which face resistance from House Republicans. His push for overhauling immigration laws could get a warmer reception. It is one of the few major issues in which badly divided Republicans and Democrats can find common ground. Republicans have long opposed relaxing immigration laws, but are reconsidering their positions as they try to appeal to Hispanics, a growing part of the U.S. electorate that has overwhelmingly favored Democrats.

One of the leading Republican voices for immigration reform, Sen. Marco Rubio, delivered the official Republican response. Rubio, a 41-year-old Cuban-American, is one of the party’s brightest stars and a possible 2016 presidential candidate. But in a sign of the divisions in the party, another, unofficial Republican response will be given by Rand Paul, a senator who is a favorite of the small-government tea party movement.

“On foreign policy, America continues to be indispensable to the goal of global liberty, prosperity and safeguarding human rights. The world is a better place when America is the strongest nation on earth. But we can’t remain powerful if we don’t have an economy that can afford it,” said Rubio, who spent most of his 20-minute address, criticizing the president’s economic policies.

Republicans remain united in their opposition to Obama’s proposals for more spending at a time of huge deficits. Obama said his proposals to increase spending on manufacturing, infrastructure and clean-energy technologies would be fully paid for, though he did not specify how he would offset the cost of his proposals.

“Nothing I’m proposing tonight should increase our deficit by a single dime,” Obama said.

He is also calling on Congress to prevent another potential blow to the economy on March 1, when massive, automatic spending cuts are scheduled to take place. Obama has asked lawmakers to block those cuts by approving a mix of tax increases and targeted budget cuts. Republicans oppose any further tax increases beyond those they reluctantly agreed to on the wealthiest households at the start of the year in exchange for extending tax cuts for the vast majority of Americans in effect since George W. Bush’s presidency.

“He’s gotten all the revenue he’s going to get,” the Senate’s top Republican, Mitch McConnell, said before the speech.

While Obama makes his case for greater gun control, first lady Michelle Obama was sitting with the parents of a Chicago teenager shot and killed just days after she had performed at the president’s inauguration last month. Twenty-two House members have invited people affected by gun violence, according to Jim Langevin, a Democratic congressman who helped with the effort. And Republican congressman Steve Stockman said he invited rocker Ted Nugent, a long-time gun control opponent who last year said he would end up “dead or in jail” if Obama won re-election.