Islamic State attacked villages near the only useable road that links the government-controlled cities of Aleppo and Homs on Thursday, killing many residents, Syrian state media and a Britain-based war monitoring group said.
The Syrian Observatory for Human Rights, said 52 people, civilians and fighters on both sides, had been killed and dozens injured. At least 25 were civilians, including five children, and three of them died in execution-style killings, it said.
State-run SANA news agency said that Islamic State fighters killed 20 people in the village of Aqarib al-Safi -- east of Hama city before the army and allied militia repulsed the attack.
The Observatory said government forces and their allies took back Aqarib al-Safi and nearby positions after heavy clashes, reversing the gains Islamic State made on Thursday.
The militants had said earlier on social media that they had captured the village.
Many of the people in the area belong to the Ismaili sect, an offshoot of Shi'ite Islam, and would be regarded by Islamic State as infidels. In 2015, Islamic State killed 46 civilians in the nearby al-Mabouja village, the Observatory said.
The army and its allies hold the road and a small strip of land on each side, with Islamic State controlling the eastern area and Syrian rebel groups the west.
The Observatory said Thursday's attack was the most violent so far this year by Islamic State along the road.
Islamic State has recently lost large swathes of territory, mainly in the north, to separate military campaigns, including by the Russian-backed Syrian army and U.S.-backed militias.
The jihadist group still mounts attacks in Syria, however, including a swift advance in December to capture Palmyra, which it held for several weeks before the army retook the city.
Separately, Syrian state television said Islamic State shelled a government-held district in the eastern province of Deir al-Zor also killed 13 people on Thursday, many of them children.
Syria's conflict, now in its seventh year, has killed hundreds of thousands of people. The multi-sided war has drawn in global powers, made half the country's population homeless, and allowed ultra-hardline jihadists to expand.