President Trump entered the new year facing flare-ups of long-burning crises with two old adversaries — Iran and North Korea — that are directly challenging his claim to have reasserted American power around the world.

While the Iranian-backed attack on the United States Embassy in Baghdad seemed to be under control, it played to Mr. Trump’s longtime worry that American diplomats and troops in the Middle East are easy targets and his longtime position that the United States must pull back from the region.

In North Korea, Kim Jong-un’s declaration on Wednesday that the world would “witness a new strategic weapon” seemed to be the end of an 18-month experiment in which Mr. Trump believed his force of personality — and vague promises of economic development — would wipe away a problem that plagued the last 12 of his predecessors.

The timing of these new challenges is critical: Both the Iranians and the North Koreans seem to sense the vulnerability of a president under impeachment and facing re-election, even if they are often clumsy as they try to play those events to their advantage.