Three men opened fire with machine guns at the al-Furat Cafe in the mainly Shia town of Balad early on Friday.
The assailants fled and hours later one blew himself up after being cornered by Shia militiamen, killing four of them.
In a claim of responsibility, IS said the attack had targeted militiamen and did not mention any connection to Real.
But a statement from Real Madrid said 16 members of a supporters club had died in the attack.
"The club expresses its great sadness and offers its regards and condolences to the families and friends of the victims," the statement said.
A correspondent for the Reuters news agency reported seeing the burned body of one of the suspected assailants outside the cafe.
Residents said they had found the man hiding in a nearby house after the attack and burned him alive after he confessed, the Reuters correspondent added.
Javier Tebas Medrano, the president of Spain's La Liga, said he was appalled by the incident.
"Terrorism has attacked football. We are with the victims and their families," he wrote on Twitter. "We were going to travel this month [to Iraq], but it was put off for security reasons. We will be back to support the people of Iraq."
Real Madrid said its players will wear symbolic black armbands in their league match on Saturday against Deportivo La Coruna.
Balad, about 80km (50 miles) north of the capital Baghdad, was overran by IS militants in June 2014, when they routed the Iraqi army and seized control of large swathes northern and western Iraq.
The town was recaptured by security forces and Shia militiamen a month later, and is currently about 40km from the nearest frontline with IS.
The cafe attack came two days after more than 90 people were killed in three suicide car bombings in Baghdad. Two of the three attacks were in Shia areas.
Iraq's most revered Shia cleric, Grand Ayatollah Ali Sistani, condemned the bombings on Friday and said the government was ultimately responsible for security breaches in the capital and elsewhere.
IS, a Sunni jihadist group, considers Shia to be irredeemable apostates.
Islamic State militants have attacked a cafe in Iraq frequented by supporters of the Spanish football club Real Madrid, killing at least 12 people.