WASHINGTON – Defense Secretary James Mattis rallied US troops abroad urging them to “hold the line” as the United States deals with its “problems.”

In an impromptu speech that has since gone viral, the four-star general praised the troops as an inspiration for the divided country.

“Just hold the line until our country gets back to understanding and respecting each other, and showing it — of being friendly to one another, you know, that Americans owe to one another,” Mattis told them.

That would have been in the aftermath of the racist Charlottesville, Va. violence.

The video shows Mattis, in a suit, introducing himself to the troops and thanking them for choosing service.

“My name’s Mattis. I work at the Department of Defense,” the plain-spoken defense chief said.

“And thanks for being out here, OK? I know at times you wonder if anybody knows … The only way this great big experiment you and I call America is going to survive is if we got tough hombres like you.”

Mattis, who is also dealing with implementing President Trump’s transgender military ban, told service members: “You’re a great example for our country right now. It’s got a few problems. You know it and I know it. It’s got problems that we don’t have in the military.

“And you just hold the line, my fine young soldiers, sailors, airmen, Marines.”

Mattis told the troops it’s because of them he “flunked” retirement.

“The only reason I came back is to serve alongside young people like you who are so selfless and, frankly, so rambunctious. It’s a pleasure to be around you all,” he said. “Take care of each other out here.”