President Donald Trump's public criticism of European allies may put the nation at risk, former Defense Secretary William Cohen told CNBC on Wednesday.

"Frankly, we can not defend the United States without allies," said Cohen, who ran the Defense Department under former President Bill Clinton. "We need friendships in a world of great danger."

Trump, speaking in Brussels on the first leg of his European trip, Wednesday on German support for one of Europe's most contentious energy developments, the Nord Stream 2 natural gas pipeline that would run directly from Russia to Germany under the Baltic Sea. Trump said Germany is “totally controlled” by Russia, claiming it would be too reliant on Russia for energy.

The president has also frequently lamented Germany’s trade surplus with the U.S., and has threatened to slap tariffs on German cars, which would strike at the heart of the country’s export-led economy.

Cohen, now chairman and CEO geopolitical consultancy The Cohen Group, said Trump "insulting and humiliating leaders of other countries" undermines long-standing U.S. relationships.

"We've had the most successful military alliance in the history of this world," said Cohen, a former Republican U.S. senator and congressman from Maine. "It seems to be the president is going out of his way to publicly undermine that."

"Don't treat your allies worse than your enemies," he added. "You're treating your enemies better than your allies."

In response to the berating from Trump, however, Germany's Defense minister said, “I think we can cope with it."

The White House did not respond to a request for comment.

— CNBC's Sam Meredith and Natasha Turak contributed to this report.