This came even as Iraqi Prime Minister Nuri al-Maliki warned that the latest escalation of violence in his country would spill over to those countries which led a "conspiracy" against Iraq.
"The security forces backed by the air force repelled an attack by militants on the oil refinery of Baiji, just outside the city of Baiji, some 200 km north of the Iraqi capital of Baghdad, leaving some 40 militants dead," Qassim Atta, security spokesman of Prime Minister al-Maliki, said at a news conference in Baghdad.
Earlier in the day, a source from Salahudin provincial police told Xinhua that hundreds of Sunni militants, including militants linked to the Islamic State in Iraq and the Levant (ISIL), an Al Qaida offshoot, launched an attack at dawn on the refinery compound from several directions with machine guns and mortar rounds.
Fierce clashes between the attackers and the militants and mortar shelling hit a fuel storage and a large column of black smoke rose above the area, the source said.
Earlier, insurgent groups overran the city of Baiji as well as large parts of the predominantly Sunni province of Salahudin, including its capital Tikrit, some 170 km north of Iraq's capital.
In Diyala province, security forces clashed with Sunni militants in many villages near the city of Udheim, some 60 km north of the provincial capital city Baquba, leaving 19 militants dead, Qassim Atta told reporters.
Also in the province, three militants were killed in a clash with a Kurdish security force, known as Peshmerga, near the city of Jalawlaa, northeast of Baquba and some 65 km northeast of Baghdad, a provincial police source said.
Six Kurdish security members were also wounded in the clash, the source said.
In Anbar province, the troops backed by allied tribesmen, clashed with militant groups in and near the city of al-Qaim, some 330 km northwest of Baghdad, Atta said without giving further details.
Sunni militants attacked the army bases outside the town of Saqlawiyah, just north of the militant-seized city of Fallujah, some 50 km west of Baghdad, and fought fierce battles during the day, a provincial police source said without giving details about casualties.
In Iraq's northern province of Nineveh, fierce clashes continued in the city of Tal Afar, some 70 km west of the provincial capital Mosul, for the fourth day, as reinforcement troops arrived in the city airport in army helicopters, a security source told Xinhua.
The troops killed 21 militants and burned four of their vehicles during heavy fighting in al-Saray neighbourhood in eastern Tal Afar, the source said, adding that clashes also were underway in other neighbourhoods across the city during the day.
The battles in Tal Afar pushed most of its 250,000 population to flee their homes, mainly to the semi-autonomous region of Kurdistan and the city of Sinjar, some 60 km west of Tal Afar.
Tal Afar itself is the mixed city of mainly Shia and Sunni Turkomans, in addition to the Kurds and other ethnic and religious minorities.
The Sunni-majority province of Nineveh and its capital Mosul, some 400 km north of Baghdad, have long been a stronghold for insurgent groups, including Al Qaida militants, since the US-led invasion of Iraq in 2003.
Meanwhile, the fate of 40 Indian nationals working for a construction company in Mosul, who were reportedly kidnapped, was not clear, though the Indian authorities said they were working to secure their release and safety. In Tikrit, 46 Indian nurses were, however, safe and in constant touch with the Indian embassy in Baghdad and the Iraqi Red Crescent volunteers.
As clashes continued in northern Iraq, Prime Minister al-Maliki Wednesday warned that the latest escalation of violence in his country would spill over to those countries which led a "conspiracy" against Iraq.
"We will face terrorism and we will bring down the conspiracy. But be sure they will flee to you and your countries will also be burned by sectarian wars," Maliki said in his weekly televised speech, referring to the countries that Iraq earlier accused of supporting terrorist groups.
"What happened in Mosul was a setback, but not a defeat," he said, explaining the negative performance of the Iraqi security forces during the fall of the city of Mosul, the capital of Iraq's northern province of Nineveh.
"We have managed to absorb the shock in Mosul and stopped the deterioration and psychological defeat for some soldiers and leaders. We have now started our reaction and regained the initiative by conducting strikes that would continue," Xinhua quoted Maliki as saying.
The security deterioration in Iraq started June 10 when bloody clashes broke out between the Iraqi security forces and hundreds of Sunni militants who took control of Mosul and later seized swathes of territories after the Iraqi security forces withdrew from their posts in Nineveh and other predominantly Sunni provinces.
On Tuesday, a statement issued by Maliki's office said neighbouring Saudi Arabia was responsible for "financing and supporting" the insurgent groups in Iraq that led to bloodshed of Iraqis and devastation in the country.
The statement came in response to comments from the Saudi government about the situation in Iraq, which was seen by the Iraqi government as "siding with terrorism" and "interference in the Iraqi internal affairs".
"We strongly condemn such a stance," said the statement.
"The Iraqi government is holding Saudi Arabia responsible for the material and moral support that these insurgent groups gained," the statement said, adding that such support to the terrorists "makes it responsible for the crimes committed by the terrorist groups".
Saudi Arabia's government rejected in a statement Monday any foreign intervention in Iraq's affairs and urged the Iraqi government to ensure the participation of all factions of the Iraqi people in determining the future of their country on an equal footing.
The Saudi statement also called for political and constitutional reforms in Iraq, and a speedy formation of a government of national consensus that can restore security and stability, and avoid policies that will instigate religious extremism and sectarianism.