WASHINGTON — President Trump on Friday reaffirmed the longstanding United States commitment to come to the defense of any NATO members that are attacked, more than two weeks after his refusal to do so during a trip to Europe stirred resentment among America’s traditional allies.

The White House also announced that Mr. Trump will travel to Poland next month before heading to Germany for a Group of 20 summit meeting, a visit meant to reassure Eastern European allies at a time when they feel nervous about aggression by Russia after its intervention in Ukraine, which is not a NATO member.

European leaders were disappointed last month when Mr. Trump did not explicitly endorse the mutual defense doctrine articulated in Article 5 of the NATO charter while visiting the alliance headquarters in Brussels. A line in his speech was taken out at the last minute, to the chagrin of the president’s national security team.

“I’m committing the United States to Article 5,” Mr. Trump said during a news conference on Friday with President Klaus Iohannis of Romania in the White House Rose Garden. “And certainly, we are there to protect and that’s one of the reasons that I want people to make sure we have a very, very strong force by paying the kind of money necessary to have that force. But yes, absolutely, I’d be committed to Article 5.”