WASHINGTON — As President Obama was making a speech on cybersecurity Monday, hackers claiming to be ISIS took over the Twitter and YouTube accounts of the Pentagon’s Central Command.

“AMERICAN SOLDIERS, WE ARE COMING, WATCH YOUR BACK. ISIS,” hackers warned in a tweet on the US CENTCOM feed, even replacing the military logo with the title “Cyber Caliphate” over a black-and-white image of a kaffiyeh-wearing terrorist.

“We won’t stop! We know everything about you, your wives and children,’’ added another posting, which appeared under a spreadsheet of office addresses and e-mails belonging to Defense Department workers.

The hackers also listed an apparent internal list of the home addresses and e-mails of retired generals such as David Petraeus while warning, “we broke into your networks and personal devices.

You’ll see no mercy infidels.

“ISIS is already here, we are in your PCs, in each military base. With Allah’s permission we are in CENTCOM now.”

Obama was speaking to a group of students and others at the Federal Trade Commission about identity theft and online privacy issues at the time.

The first infiltrated tweet appeared at around 12:30 p.m. — right in the middle of Obama’s speech, which he started at 12:11 p.m. and finished at 1:10 p.m.

Unaware of the hack, the president crowed, “We are the country that invented the Internet. And we’re also the pioneers of this Information Age — the creators, the designers, the innovators

. . . I’m confident, if we keep at this, we can deliver the prosperity and security and privacy that all Americans deserve.’’

The hack lasted at least 30 minutes before the government took the feed down.

“This is something we’re obviously looking into and something we take seriously,’’ White House Press Secretary Josh Earnest told reporters while trying to downplay the security breach.

“There is a pretty significant difference between what is a large data breach and the hacking of a Twitter account,” he insisted.

CENTCOM later said its “initial assessment is that no classified information was posted.”

Defense Department Col. Steve Warren dismissed the hack attack as nothing more than “a big inconvenience.”

“This is spray paint on the wall,’’ he told The Post. “There was no operational impact, no breach of CENTCOM’s network or the Defense Department’s network.”

Still, CENTCOM said it was “notifying appropriate [Defense Dept.] and law-enforcement authorities about the potential release of personally identifiable information’’ regarding current and retired workers.

A federal law-enforcement source called the hack a real mess.

“This has to be one of the more embarrassing moments of Obama’s presidency — talking about cyber security and the defense department gets hacked,” the source said. “Not good!”

CENTCOM said it uses social media such as Twitter and YouTube “to put out news or messages’’ just like any organization.

The hacker postings included broad, standard plans for potential US conflicts with China and Korea, the Times of London reported, and included at least one map that was already online. The China posting detailed locations of its military bases and bore the logo of the MIT Lincoln Laboratory, a US government-funded center.

Some posted documents also were tied to Iran, like one showing a map of Scud missile ranges from the country.

The hackers also infiltrated CENTCOM’s YouTube account, posting at least two propaganda videos, including one titled, “FLAMES OF WAR’’ and featuring footage of US soldiers carrying a wounded or dead comrade.

Additional reporting by Sophia Rosenbaum and Kate Sheehy