WASHINGTON — Things were on a clear course as far as President Trump’s re-election campaign was concerned. The impeachment proceedings unfolding on Capitol Hill had proved to be a boost for volunteer recruitment and small-dollar donations. The year ended with a blockbuster jobs report and the unemployment rate falling to 3.5 percent, its lowest level since 1969.

Mr. Trump was ready to aggressively attack a Democratic field he and his advisers viewed as weak across the board. Few if any of the president’s top campaign aides were looking to change the channel.

But Mr. Trump’s decision to authorize the killing of Maj. Gen. Qassim Suleimani, which he has described to friends and allies as a necessary action he was forced to take, has opened up a more uncertain political reality as the president enters an election year. That uncertainty was on display Tuesday night when Iran fired missiles at American forces in Iraq, in its first act of retaliation.

Some advisers have highlighted to Mr. Trump the short-term lift the strike could give his re-election prospects, and his campaign has run nearly 800 distinct Facebook ads trumpeting the killing, according to Acronym, a progressive digital strategy group. The ads refer to Mr. Trump’s “leadership as commander in chief” and direct voters to an “Official Trump Military Survey,” which acts as a portal to his campaign website.