Islamic State (IS) suicide bombers and fighters have attacked the centre of Iraq's northern oil refinery town of Baij, forcing the army and Shi'ite fighters to pull back.

The town of Baiji and its refinery - Iraq's largest - have been a battlefront for more than a year. The hardline Islamists seized the town in June 2014 as they swept through much of northern Iraq towards the capital Baghdad.

Control of Baiji neighbourhoods has changed hands many times during the conflict. The latest IS offensive comes after authorities said they controlled nearly the whole town and expected to drive insurgents from the refinery within days.

The militants attacked on Saturday nihgt with two suicide car bombings. The blasts were followed by fierce clashes that lasted until midnight and drove the army and mainly Shi'ite Hashd Shaabi forces from the centre of town, two army colonels said.

Baiji mayor Mahmoud al-Jabouri said there had been a pattern of withdrawals by IS fighters in the town followed by counter-offensives.

He said: "Their lethal weapons are suicide attacks and snipers, and this is why we have fighting back and forth."

Army officers said the army and Hashd groups were preparing a response. "IS fighters are still holding positions in three neighbourhoods in Baiji and they are still receiving reinforcements," said one of the army colonels.

In Anbar province west of Baghdad, witnesses said two rockets hit a crowd in the IS-controlled provincial capital Ramadi on Saturday evening, killing at least 18 people.

They said a group of people had gathered after the daily Ramadan fast to play Muhaibis, a game where players have to identify a member of the opposing team who is hiding a ring.

"I heard a blast and saw fire coming from Dolphin Square. I ran to the place and saw vehicles carrying bodies and wounded covered with blood. They were innocent people playing a ring game; they were not making bombs," said Haj Thamir Ahmed, a Ramadi resident who lives nearby.

In northwest Baghdad, at least three people were killed and 11 wounded when a bomb went off near a restaurant in the mainly Shi'ite district of Shulaa. Another two people were killed by a bomb in Hussainiya on the city's northern outskirts.

There was no immediate claim of responsibility for those attacks, but statements in the name of IS said the group carried car bombings on Saturday evening in Baghdad and Balad Roz which killed 10 people.