PALM BEACH, Fla. — The images were heartbreaking: Children gasping and choking for breath, their mouths foaming. A grief-stricken father, cradling the lifeless bodies of his two children, swaddled in white blankets. But they were also familiar, a harrowing flashback to 2013, when the Syrian government unleashed the last major poison gas attack on its own people.

This time, though, a new American president was seeing the pictures and absorbing the horror.

Donald J. Trump has always taken pride in his readiness to act on instinct, whether in real estate or reality television. On Thursday, an emotional President Trump took the greatest risk of his young presidency, ordering a retaliatory missile strike on Syria for its latest chemical weapons attack. In a dizzying series of days, he upended a foreign policy doctrine based on putting America first and avoiding messy conflicts in distant lands.

Mr. Trump’s advisers framed his decision in the dry language of international norms and strategic deterrence. In truth, it was an emotional act by a man suddenly aware that the world’s problems were now his — and that turning away, to him, was not an option.

“I will tell you,” he said to reporters in the White House Rose Garden on Wednesday, “that attack on children yesterday had a big impact on me — big impact. That was a horrible, horrible thing. And I’ve been watching it and seeing it, and it doesn’t get any worse than that.”