Turkish forces have been using the Bashiqa camp, just outside Mosul, to train local Iraqi fighters to retake the city from IS.
"Eighteen members of the Daesh terror organisation who wanted to infiltrate Bashiqa were neutralised," Erdogan said in televised comments after Friday prayers in Istanbul, using another name for the IS group.
"None of our soldiers were wounded," he added.
It was not immediately clear what nature of attack the jihadists had launched but Erdogan said that the Turkish forces were ready to repel any kind of assault.
More From This Section
The presence of the Turkish troops, while welcomed by the local authorities in Iraqi Kurdistan, has become a bone of contention with the central Iraqi government which angrily called for the Turkish troops to leave.
Turkey in December withdrew some of the troops after also coming under US pressure. But it is unclear how many remain at the camp.
Erdogan said Friday the latest attack showed how right Turkey was to station armed forces at the camp to protect the Turkish officers who are providing the training for the Iraqis.
Four Turkish soldiers were wounded on December 16 when IS jihadists fired mortars on the training camp, in an attack that also left two Iraqis dead.