WASHINGTON — President Barack Obama said Sunday that he would use military action to prevent Iran from securing nuclear weapons, even as he urged Israel and its supporters to refrain from “loose talk of war” and allow diplomacy and “crippling sanctions” to work.

Speaking a day before a meeting with Israeli Prime Minister Benjamin Netanyahu, Obama told the influential American Israel Public Affairs Committee that he has “Israel’s back” and is unalterably opposed to Iran getting a nuclear weapon.

“Iran’s leaders should know that I do not have a policy of containment; I have a policy to prevent Iran from obtaining a nuclear weapon,” he said. “I’ve made clear time and again during the course of my presidency, I will not hesitate to use force when it is necessary to defend the United States and its interests.”

Israel is afraid that Iran — which says its nuclear program is for domestic reasons — could reach what the Israeli defense minister calls a “zone of immunity,” when Israel would be unable to take out Iran’s nuclear program. Obama argued there is time for diplomacy, “backed by pressure,” to work.

“Israel and the United States have an interest in seeing this challenge resolved diplomatically,” Obama said, speaking to the AIPAC policy conference that organizers said was attended by 13,000 people. “After all, the only way to truly solve this problem is for the Iranian government to make a decision to forsake nuclear weapons.”

Obama, whose tough early stand against Israel’s building of settlements in the predominantly Palestinian West Bank has led some Jewish voters to view him warily, used most of his 34-minute speech to defend his record on Israel and implore the audience to trust him. He called his commitment to Israel’s security “unprecedented,” listing examples such as speaking at the United Nations last fall against a Palestinian bid for recognition.

“Over the last three years, as president of the United States, I have kept my commitments to the state of Israel,” Obama said. “At every crucial juncture — at every fork in the road — we have been there for Israel. Every single time.”

He suggested that “if during this political season you hear some questions regarding my administration’s support for Israel, remember that it’s not backed up by the facts.

“There should not be a shred of doubt by now,” he said. “When the chips are down, I have Israel’s back.”

Before Obama took the stage at the Washington Convention Center, Liz Cheney, a deputy assistant secretary of state for Near East affairs in the George W. Bush administration, said Obama has been more interested in constraining Israel than Iran, and that “no president has done more to delegitimize and undermine” Israel’s security than Obama.

But former Rep. Jane Harman, D-Calif., who sat on a panel with Cheney, suggested it was a “grave mistake to turn Israel into a political football.”

Polls suggest that most Americans are opposed to military intervention in Iran. A small band of anti-war protesters held court outside the convention center, holding signs protesting Israel and what they fear is a run-up to war.

Obama insisted the “entire world” has an interest in preventing Iran from acquiring nuclear weapons, because they could fall into the hands of terrorists and would compel other countries to get their own.

And he argued that he’s had success in tightening a noose around Iran, with Russia and China joining the effort.

But he sought to assure Netanyahu — and Iran — that the U.S. would support Israel in defending itself.

“We all prefer to resolve this issue diplomatically,” he said. “Having said that, Iran’s leaders should have no doubt about the resolve of the United States, just as they should not doubt Israel’s sovereign right to make its own decisions about what is required to meet its security needs.”

Netanyahu, who is said to want greater specificity from the U.S. and a promise of military intervention, told reporters that the most significant part of Obama’s speech was that Israel “must be able to defend itself, by itself, against any threat.”

Reuters said Netanyahu in Ottawa said that he “very much appreciates that fact that Obama reiterated the position that Iran must not be allowed to develop nuclear weapons, and that all options are on the table.”

Israeli President Shimon Peres, who will receive the highest U.S. civilian honor, the Presidential Medal of Freedom, thanked Obama for “being such a good friend” of Israel and insisted “there is no space” between Israel and the U.S. over Iran.

“President Obama made it clear that the U.S. will never permit Iran to become nuclear,” he said.

But, he said, “If we are forced to fight, trust me, we will prevail.”

Obama cautioned against “too much loose talk of war,” saying it has benefited only the Iranian government by driving up the price of oil.