BEIRUT, May 18 (Reuters) - Islamic State attacked a village near the main road between Aleppo and Homs on Thursday, killing many residents, Syrian state media and a war monitor said.

The jihadist group has lost large swathes of territory recently in Syria after expanding rapidly in 2014 and 2015, and is under assault from a U.S.-backed coalition of Arab and Kurdish militias as well as by the army, backed by Russia.

However, it still mounts occasional counter attacks including a swift advance in December to capture Palmyra, which it held for several weeks before the army retook the city.

The insurgents said on a social media feed it had captured the village of Aqarib al-Safi, but the government-run SANA news agency reported that the attack had been repulsed.

SANA said Islamic State fighters had killed 20 people in the village before the army and allied militia drove them away. The Syrian Observatory for Human Rights reported that clashes were still going on there and in the village of al-Saboura.

The Observatory said that at least 34 people, including both civilians and fighters on both sides, had been killed and that dozens had been injured.

Many of the people who live in that part of Syria 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 a nearby town, the Observatory said.

The Observatory, a Britain-based monitor of the war, said that at least 15 of those killed were civilians, five of them children, and that three of them died in execution-style killings.

The villages are north of al-Salamiya close to the only road still useable between Aleppo and other parts of Syria held by the government.

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, including hardline Islamists, the western area.

The Observatory said the attack was the most violent so far this year by Islamic State on the road.

Syria's civil war began in 2011 after mass protests against the rule of President Bashar al-Assad and has killed hundreds of thousands of people, driven half the country's population from their homes and dragged in world powers.

(Reporting by Angus McDowall; Editing by Louise Ireland) ((angus.mcdowall@thomsonreuters.com; Reuters Messaging: angus.mcdowall.thomsonreuters.com@reuters.net))