Bloodthirsty militants in Iraq released a horrific video Tuesday that shows the beheading of American photojournalist James Wright Foley — with the execution aimed at forcing President Obama to end US airstrikes.

Foley, 40, who was kidnapped in Syria nearly two years ago, was forced to recite anti-American hatred before a masked Islamic State killer put the knife to his neck.

The video — posted on YouTube before being yanked — shows Foley dressed in prisoner orange and on his knees in the desert. His head is shaved. Behind him is his knife-wielding killer, covered from head to toe in black. Its title is “A Message to America.”

“Any attempt by you, Obama, to deny Muslims liberty and safety under the Islamic caliphate will result in the bloodshed of your people,” the terrorist says in reference to US airstrikes against the Islamic State.

Foley — last seen on Thanksgiving 2012 while working for Agence France-Presse — earlier reads a clearly coerced statement.

“I call on my friends, family and loved ones to rise up against my real killers, the US government. My message to my beloved parents: Save me some dignity and don’t accept any meager compensation for my death from the same people who effectively put the last nail in my coffin,” he says.

“I call on my brother, who is in the Air Force. I call on you, John. Think about who made the decision to bomb Iraq. Who did they really kill? Did they think about me, you and our family when they made that decision? I died that day, John. When your colleagues dropped that bomb, they signed my death certificate. I wish I had more time. I wish I had the hope of seeing my family one more time.”

As a final insult, his last forced words were, “I guess, all in all, I wish I wasn’t American.”

The video then cuts to a gruesome image of Foley’s blood-soaked head, detached from his body and resting on his back near his shackled hands.

The militants then display another kneeling and shackled American — Time journalist Steven Joel Sotloff — and the group says he is next unless the United States backs off.

Sotloff was abducted in Syria in August 2013.

“The life of this American citizen, Obama, depends on your next decision,” the masked man says.

In a statement posted on a Facebook page affiliated with the Foley family, James’ mother, Diane, said, “We have never been prouder of our son Jim. He gave his life trying to expose the world to the suffering of the Syrian people.

“We thank Jim for all the joy he gave us. He was an extraordinary son, brother, journalist and person.”

She also called for an end to Islamic State brutality, saying: “We implore the kidnappers to spare the lives of the remaining hostages. Like Jim, they are innocents.”

Obama was briefed on Foley’s barbaric murder while flying on Air Force One to Martha’s Vineyard to resume his vacation.

Two US officials said they believe the video is authentic, although White House National Security Council spokeswoman Caitlin Hayden said US intelligence is still analyzing it.

“If genuine, we are appalled by the brutal murder of an innocent American journalist and we express our deepest condolences to his family and friends,” Hayden said.

The Washington Post reported that European officials were going over the video to compare the voice of the executioner — who seemed to have a trace of a British accent — with ex-Guantanamo Bay inmates who had British ties.

The Islamic State — also known as the Islamic State in Iraq and Syria, or ISIS — had warned the United States of the potential murder in an earlier video, saying, “We will drown all of you in blood” in revenge.

Senior US officials with direct knowledge of the situation said the Islamic State recently threatened to kill Foley to avenge the airstrikes that freed ethnic Yazidis who had been trapped by the terrorists on Mount Sinjar, and that helped Kurds retake the crucial Mosul dam from the Islamic State.

Foley family friend Holly Rene, who lives in their hometown of Rochester, NH, told The Post, “These savages have got to be stopped. It’s coming West.”

She said the family is “falling apart with grief.”

Foley, one of five children, had been a hostage before, having been held in Libya for 45 days in 2011.

He graduated from Marquette University in 1996 and later studied journalism at Northwestern.

He penned a letter to Marquette Magazine thanking the community for its prayers when he was captured in Tripoli with two colleagues.

“If nothing else, prayer was the glue that enabled my freedom, an inner freedom first and later the miracle of being released during a war in which the regime had no real incentive to free us,” Foley wrote. “It didn’t make sense, but faith did.”