BAGHDAD—Suspected Islamic State militants ambushed a military patrol in northern Iraq late Wednesday, killing two Iraqi soldiers and wounding three others, Iraqi security officials said, in the latest sign that the group is attempting a violent resurgence.

There was no immediate claim of responsibility for the attack near the city of Kirkuk, but the officials said they suspected fighters from Islamic State. Gunmen opened fire on Iraqi troops riding in two military vehicles, which were also targeted by roadside bombs, according to the officials.

It was the fourth major attack believed to have been carried out by Islamic State since Dec. 14, leaving at least 14 soldiers and police officers and 11 civilians dead in one of the most violent series of attacks by the militant group recently.

Islamic State has managed to sustain a low-level insurgency in Syria and Iraq despite years of military operations aimed at crushing it. The militant group launched a prison break in northeastern Syria in January that triggered days of street-to-street fighting with Syrian militia fighters and U.S. soldiers. More than 500 people died in the attack and the ensuing battle in the city of Hasakah.

Meeting with military commanders Wednesday, Iraqi Prime Minister Mohammed al-Sudani blamed the latest violence on the remnants of Islamic State, which the U.S. military and its allies declared they had largely defeated in 2019 after expelling the group from most of Iraq and eastern Syria.

On Wednesday, Mr. Sudani ordered Iraqi commanders to redeploy forces to areas in the north, a former Islamic State stronghold where two of the attacks occurred, and to step up operations aimed at preventing the group’s resurgence, according to a statement by his office.

“There is a clear failure that led to this tragedy,” Mr. Sudani was quoted as saying in Iraqi media after the second attack in Kirkuk province on Sunday, when nine police officers were killed by roadside bombs.

Iraq’s air force carried out airstrikes Wednesday against what it claimed was an Islamic State hideout in Nineveh province, killing five militants, according to a statement by military joint operations command.

Iraq’s military intelligence service said it had arrested 24 militants in recent days in Baghdad and Kirkuk, as well as the provinces of Anbar, Diyala and Maysan.

“As we promised, the reply to the cowardly acts of Daesh will be tough,” the military said, using the Arabic name for Islamic State.

The recent spate of attacks began in mid-December, when an Iraqi army patrol in Tarmia, an area in northern Baghdad, was ambushed in a roadside bomb attack, killing three soldiers and wounding three more.

The Sunday attack in Kirkuk killed nine police, including a senior officer. The following day in Diyala province, north of Baghdad, eight civilians were killed and nine others were wounded by a roadside bomb and gunfire.

Islamic State took over swaths of Iraq and Syria beginning in 2014, forcing the Obama administration to send U.S. troops back to Iraq to assist Iraqi military forces, which had largely collapsed as the militants swept into Iraq from Syria. The U.S. has retained about 2,000 troops in Iraq and another 600 in Syria, mostly to train and advise local forces.

Write to David S. Cloud at david.cloud@wsj.com