"The attack which was launched at 8:00 pm (1700 GMT on Tuesday) was foiled. It lasted four hours and we killed 34 IS members," Sirwan Barzani, the local peshmerga commander, told AFP.
He said around 300 jihadists had attacked the villages of Sultan Abdallah and Tal al-Rim, between the towns of Gweyr and Makhmur, an area about 40 kilometres (25 miles) southwest of Erbil.
"Daesh (IS) was not able to use heavy military vehicles or car bombs due to trenches dug out by peshmerga on the front lines," said Barzani, also the nephew of Kurdish leader Massud Barzani.
Signup to our newsletter and follow us on Facebook and Twitter!
He said the IS offensive achieved no gains and added that his operation received air support from the US-led coalition which has carried out hundreds of strikes against IS since August 2014.
"The clashes are over now. We are collecting their bodies," said Najat Ali, the deputy peshmerga commander on the Makhmur front.
Gweyr and Makhmur were among the very first targets of US air strikes against the jihadists six months ago.
An IS advance had brought the jihadists to within striking distance of Erbil, the capital of the autonomous region of Kurdistan.
The jihadists have continued to attack the area nonetheless, including in a surprise offensive last month when they used boats to cross the Zab river and killed at least 26 members of the Kurdish security forces.