President Trump on Wednesday had a testy exchange with the head of NATO when he asked about energy agreements between Russia and several European countries.

Trump repeatedly pressed Jens Stoltenberg, NATO's secretary general, on why the U.S. continued to pay money to the military alliance while countries continue to purchase energy from Moscow.

“We are stronger together,” Stoltenberg insisted, but acknowledged that there can be differences among allies.

Still, Trump persisted.

“But how can you be together when you’re getting energy from the group you want protection from?” the president asked.

Trump used Germany as an example. He asked Stoltenberg to explain why Berlin was getting energy from Moscow, and asserted that Germany was "totally controlled" by and "captive to Russia" over a pipeline project.

The president appeared to be referring to the Nord Stream 2 pipeline that would double the amount of gas Russia can send directly to Germany, skirting transit countries such as Ukraine. The project is opposed by the U.S. and some European Union members.

Trump said of Germany: "We're supposed to protect you against Russia and yet you make this deal with Russia."

“Explain that,” Trump said. “It can’t be explained."

The sharp exchange occured hours before Trump arrived at NATO headquarters for additional meetings.

The U.S. role in NATO has been a focal point for Trump since before he was elected president. He tweeted Monday that the situation was “not fair, nor is it acceptable.” He said NATO benefits Europe “far more than it does the U.S.”

Trump has called upon NATO allies to meet commitments to spend 2 percent of their GDP on defense.

He tweeted en route from Washington that European countries "want us to happily defend them through NATO, and nicely pay for it. Just doesn't work!"

Brussels is the first stop of Trump's week-long European tour that will include a visit to Britain and a meeting in Finland with Russian President Vladimir Putin.

Fox News' Kristin Brown and the Associated Press contributed to this report.