President Trump’s tenure as commander in chief came to a dramatic turning point on Thursday night as he found himself torn between his own competing advisers and his own competing instincts, teetering on the edge of the kind of military action he came to office vowing not to take.

In a volatile day of internal debates and an on-again, off-again strike against Iran, Mr. Trump confronted the essential conflict of his approach to national security. For two and a half years, he has veered between bellicose threats against America’s enemies and promises to get the United States out of the intractable wars of the Middle East. Now he had to choose.

Even as the military machinery cranked up to launch an attack on Iran on his orders in response to the shooting down of an unmanned American spy drone, Mr. Trump called it off, opting for restraint over retaliation, at least for now. The argument may not be over. Administration officials would not divulge many details of the discussion. But no one doubted this could be a defining juncture in Mr. Trump’s presidency.

Mr. Trump approved strikes on Iran, but then abruptly pulled back.

This moment of truth was probably inevitable since the day in 2018 that Mr. Trump withdrew the United States from the international nuclear agreement with Iran negotiated by President Barack Obama and decided to unilaterally reimpose crippling sanctions. With its economy crumbling, Iran was always prone to lash out, forcing Mr. Trump to choose between war and peace.