President Donald Trump said Thursday that the United States will not attack Iran before the Nov. 3 midterm election, explicitly linking the timing of potential military action to the domestic political calendar.

"We will not be attacking Iran at any time prior to the Midterm Elections," Trump posted on Truth Social. He added that the U.S. was having "productive discussions" with Tehran while maintaining a naval blockade and reiterating that Iran would not be allowed to obtain a nuclear weapon.

The statement reversed Trump's posture from less than 24 hours earlier. On Wednesday night at a campaign rally, he told reporters his administration was considering renewed strikes against Tehran before the election. That comment sent oil prices higher amid escalation fears. Brent crude rose more than 4 percent Thursday to above $104 a barrel.

Trump also said a deal with Iran was "not really something that I wanted to do" at Wednesday's rally, before shifting to a more diplomatic tone Thursday.

Public support for military action against Iran has declined. Only 31 percent of Americans supported U.S. military action against Iran in an August Reuters/Ipsos poll, down from 37 percent in March. Eighty-three percent of those surveyed expected the conflict to be prolonged.

Oil prices reflect broader voter concerns about affordability. Gas prices have climbed roughly 40 percent in the past year, reaching a national average of $4.36 per gallon Thursday, up from $2.98 before the war began in late February, according to AAA data. Poll after poll has ranked the cost of living among voters' top concerns heading into the midterm election.

The vulnerability on energy costs has shown on the campaign trail. Numerous Republican candidates in competitive congressional races have distanced themselves from Trump, often over the Iran war.

Trump's statement leaves the door open to military action after Election Day. He also claimed that 22 million barrels of oil moved through the Strait of Hormuz overnight with none coming from or going to Iran, though CNBC noted it has not independently verified that figure.