Secretary of State John F. Kerry urged Kurdish leaders Tuesday to remain part of Iraq, as fighters from local Sunni tribes wrested control of at least part of Iraq’s largest oil refinery after battling for days with government troops over the key facility.

Armed tribal factions from the Baiji area, mainly the dominant al-Kaisi tribe, breached the refinery complex 140 miles northwest of Baghdad, according to refinery workers and an Interior Ministry official in Baghdad. A tribal council official said Tuesday, “We now control 90 percent of the refinery.”

There were conflicting accounts later in the day about who was in charge at the refinery. Iraqi soldiers who arrived in Irbil after fleeing the refinery Monday night said fighters from the Islamic State of Iraq and Syria (ISIS) spearheaded the assault on the complex. And the government in Baghdad insisted it was still in control.

The tribes negotiated a cease-fire and surrender, the refinery workers said. About 450 Iraqi army officers had been in the refinery, and some took off their uniforms and put on blue refinery coveralls before leaving, according to their account. The tribes arranged buses to take them away, the workers said. Before the surrender, the attackers had control of a residential complex across the street from the refinery.

It was not immediately clear what kind of relationship the tribes have with ISIS, which has waged a lightning offensive across northern Iraq over the past two weeks and whose fighters been battling for control of the Baiji complex.

In Baghdad, Iraqi military spokesman Qassim Atta, whose daily televised news updates have been regularly contradicted by reports from the field, claimed that the refinery remains in government hands.

“We stress that the refinery is under the control and protection of security forces fully,” he said. He added that Prime Minister Nouri al-Maliki has promoted all security forces fighting in the refinery by one rank, praising their “magnificent defense.”

A Western diplomat said it remained unclear Tuesday who controlled the Baiji refinery.

“This really is a crisis,” the diplomat said, speaking on the condition of anonymity under news briefing ground rules. “It poses questions as to Iraq’s continued existence as a state. What we’ve got is Sunnis controlling Sunni territory, Shias controlling Shia territory, Kurds controlling Kurdish territory.”

In launching its offensive, ISIS has been filling in “gaps in territory and pushing out West toward the borders,” he said. “There’s a question as to whether or not they control all of the Jordan border. Despite the denials, our sense is that they probably do, and are even touching on the Saudi border, which is disturbing.”

The developments came as Kerry met with Kurdish leaders Tuesday in the northern city of Irbil, the Kurdish regional capital. After talks in Baghdad on Monday, Kerry spent the night in Jordan, then returned to Iraq for his second visit in two days.

During the talks in Irbil, he urged Iraq’s restive Kurds to work alongside the central government in Baghdad to combat the threat posed by ISIS, a radical Sunni Muslim group formerly known as al-Qaeda in Iraq. The group has since broken away from al-Qaeda, which has repudiated its methods as too extreme.

How the Islamic State is carving out a new country

The Kurds have seized the key northern oil city of Kirkuk amid the ISIS offensive. Kurdish leaders are now suggesting they might seek independence, the beginning of a possible breakup of the country.

“We are facing a new reality and a new Iraq,” Massoud Barzani, president of the semiautonomous Kurdish government, told Kerry at the start of their meeting Tuesday.

An independent Kurdistan is a long-held goal for many in Iraq’s Kurdish minority, which numbers about 6.5 million people. Some Kurdish leaders see an opportunity in the rapid advance of the insurgents and the slow, disorganized response by the Arab-led government.

In Baiji, attackers whose identities were not immediately clear began assaulting the refinery complex last week, but government forces backed by Iraqi army helicopters were able to repel them, according to refinery employees and officials of the Kirkuk-based North Oil Co., which supplies Baiji with crude.

On Monday, however, attackers were able to breach the complex and gain the upper hand in the ensuing fighting with government forces, who did not have helicopter support, the sources said. The security forces negotiated a cease-fire and surrender to the attackers, brokered by the tribes, and most of the soldiers left.

According to an official of the Baiji branch of the Military Council of the Revolutionary Tribes, a Sunni self-defense organization that includes the al-Kaisi tribe and other clans in the area, about 50 government troops remain holed up in a part of the refinery.

The official, who gave his name as Khalid al-Iraqi, said tribal fighters were joined by a smaller number of ISIS insurgents in attacking the refinery. He said the Military Council now controls the refinery. ISIS was described as not strong enough in the area to give orders and as the tribes’ ally of convenience.

However, two Iraqi soldiers who took part in the defense of the refinery said Tuesday that ISIS fighters were doing most of the attacking. The soldiers, part of a group of about a dozen who endorsed the account, were interviewed on the outskirts of Irbil after having fled Baiji late Monday.

The security crisis in the country could present a justification and an opportunity for Kurds to pull out of the government in Baghdad, which Kurds have long complained sidelines their interests. Kerry is trying to persuade skeptical Kurdish leaders not to withdraw and to join in forming a new central government.

“This is a very critical time in Iraq,” Kerry said at the start of his meeting with Barzani, and the process of forming a new government in Baghdad following parliamentary elections “is the central challenge that we face.”

Kerry said he wanted to talk to assembled Kurdish leaders “about how the government formation process can produce the broad-based inclusive government that all Iraqis I have talked to are demanding.”

Barzani’s support for the Iraqi government is vital because the Kurds, about 20 percent of Iraq’s population, usually vote united, giving them a powerful position in Iraq’s national political process.

Rudaw, Barzani’s radio station, reported that the meeting between Kerry and Kurdish political leaders was friendly. It said that Kerry, upon meeting Falah Mustafa, the head of the Kurds’ foreign relations office, joked that Mustafa was essentially the foreign minister, words that people here interpreted as an implicit nod to the Kurds’ growing autonomy.

The top U.S. diplomat met with Maliki, a Shiite, in Baghdad on Monday with a message of unity. U.S. officials are arguing that Iraq risks collapse unless a new coalition representing all sects and ethnicities is quickly formed.

That argument is harder to make in the Kurdish region, which has several vast oil fields and a long history of at least partial self-rule.

Barzani and Maliki have had a tense relationship for years. Recently, sparks flew again when the Kurdish regional government began exporting oil through Turkey without giving Baghdad a required share of the profits. The Kurdish region has security and economic stability unmatched across the rest of the Iraq.

Barzani was blunt in an interview Monday with CNN.

“Iraq is obviously falling apart,” Barzani said. “We did not cause the collapse of Iraq. It is others who did. And we cannot remain hostages for the unknown,” he said through an interpreter.

“"The time is here for the Kurdistan people to determine their future, and the decision of the people is what we are going to uphold.”

Kerry thanked the Kurdish pesh merga fighters for what he called recent cooperation with Iraqi army forces to confront ISIS.

The pesh merga took control of Kirkuk two weeks ago, after the army fled an ISIS advance. The city Kurds regard as their historical capital is located just outside the Kurdish-administered region and represents a major prize for Kurdish leaders.

Ahead of Kerry's visit, a senior State Department official said Kerry would argue that Kurds are better off inside the Iraqi government and that Iraq is better off for having them.

“If they decide to withdraw from the Baghdad political process, it will accelerate a lot of the negative trends,” the official said. The official spoke on condition of anonymity to outline Kerry’s agenda.

U.S. military advisers began moving into position Monday, hours after Washington and Baghdad signed an immunity agreement. Kerry said the United States will protect its national security interests even if Iraqis cannot bridge their widening sectarian and political divides.

Hauslohner reported from Kirkuk. Loveday Morris and Liz Sly in Baghdad and Daniela Deane in London contributed to this report.