(Adds immunity for U.S. forces, paragraphs 16-17)
* Visit comes after militant gains on the border
* Kerry says Obama will not wait to support military
* Maliki to form new government on July 1, Kerry says
* Kurdish region president calls for Maliki to quit
* U.S. says its forces get immunity guarantees from Iraq
By Lesley Wroughton and Ahmed Rasheed
BAGHDAD, June 23 (Reuters) - Secretary of State John Kerry on Monday promised "intense and sustained" U.S. support for Iraq, but said the divided country would only survive if its leaders took urgent steps to bring it together.
Hours before Kerry arrived in Baghdad, Sunni tribes who have joined a militant takeover of northern Iraq seized the only legal crossing point with Jordan, security sources said, leaving troops with no presence along the entire western frontier which includes some of the Middle East's most important trade routes.
U.S. President Barack Obama has offered up to 300 American advisers to Iraq but held off granting a request by Prime Minister Nuri al-Maliki's Shi'ite Muslim-led government for air strikes to counter the two-week advance by Sunni militants.
Officials have meanwhile called for Iraqis to form an inclusive government. The insurgency has been fuelled largely by a sense of marginalisation and persecution among Iraq's Sunnis.
"The support will be intense and sustained and if Iraq's leaders take the necessary steps to bring the country together, it will be effective," Kerry told reporters in Baghdad.
He said Maliki had "on multiple occasions affirmed his commitment to July 1" as the date to start the formation of a new government bringing in more Sunnis and Kurds to share power, a move Washington is keen to see.
Iraqi and Jordanian security sources said tribal leaders were negotiating to hand the Turabil desert border post to Sunni Islamists from the Islamic State in Iraq and the Levant (ISIL) who took two main crossings with Syria in recent days and have pushed Iraqi government forces back toward Baghdad.
Iraq state television said late on Monday that the army had recaptured both the crossing with Jordan and the al-Waleed crossing with Syria. Reuters could not independently confirm reports due to security restrictions.
Ethnic Kurdish forces control a third border post with Syria in the north, leaving government troops with no presence along Iraq's 800-km (500-mile) western border.
For the insurgents, capturing the frontier is a dramatic step towards the goal of erasing the modern border altogether and building a caliphate across swaths of Syria and Iraq.
Kerry said: "Iraq faces an existential threat and Iraq's leaders have to beat that threat with the incredible urgency that it demands. The very future of Iraq depends on choices that will be made in the next days and weeks."
Washington, which withdrew its troops from Iraq in 2011 after an occupation that followed the 2003 invasion that toppled dictator Saddam Hussein, has been struggling to help Maliki's administration contain a Sunni insurgency led by ISIL, an al Qaeda offshoot which seized northern cities this month.
PRESSURE ON MALIKI
Washington is worried Maliki and fellow Shi'ites who have won U.S.-backed elections have worsened the insurgency by alienating moderate Sunnis who once fought al Qaeda but have now joined the ISIL revolt. While Washington has been careful not to say publicly it wants Maliki to step aside, Iraqi officials say such a message was delivered behind the scenes.
There was little small talk when Kerry met Maliki, the two men seated in chairs in a room with other officials.
The meeting lasted one hour and 40 minutes, after which Kerry was escorted to his car by Iraq's Foreign Minister Hoshiyar Zebari. As Kerry got in, he said: "That was good."
In Washington, officials said Iraq has given assurances to the United States that the special operations forces Obama has ordered into the country will be shielded from possible prosecution in Iraqi courts.
The Obama administration has said its decision not to leave a residual U.S. force in Iraq in 2011 stemmed from difficulty in getting a deal from Iraqi leaders to keep American troops from being tried in local courts.
Iran's Supreme Leader Ayatollah Ali Khamenei accused Washington on Sunday of trying to regain control of the country it once occupied - a charge Kerry denied.
Iraqis are due to form a new government after an election in April. Maliki's list won the most seats in parliament but would still require allies to secure a majority.
Senior Iraqi politicians, including at least one member of Maliki's own ruling list, have told Reuters that the message that Washington would be open to Maliki leaving power has been delivered in diplomatic language to Iraqi leaders.
Recent meetings between Maliki and American officials have been described as tense. According to a Western diplomat briefed on the conversations by someone attending the meetings, U.S. diplomats have informed Maliki he should accept leaving if he cannot gather a majority in parliament for a third term. U.S. officials have contested that such a message was delivered.
A close ally of Maliki has described him as having grown bitter toward the Americans in recent days over their failure to provide strong military support.
The president of Iraq's autonomous Kurdish region, which has seized on the chaos to expand its northern territory to include the oil-rich city of Kirkuk, blamed Maliki's "wrong policies" for the turn of events and joined calls for him to quit.
Massoud Barzani said Iraq was falling apart and reiterated a threat to hold a referendum on independence from the rest of the country.
"The time is now for the Kurdish people to determine their future," Barzani said in an interview with CNN. "We are living in an Iraq that is completely different from the Iraq of two weeks ago."
Jordanian army sources said Jordan's troops had been put in a state of alert in recent days along the 181-km (112-mile) border with Iraq, redeploying in some areas as part of steps to ward off "any potential or perceived security threats".
The Jordan border post was in the hands of Sunni tribesmen after government troops fled. An Iraqi tribal figure said there was a chance it would soon be passed to control of the militants, who seized the nearby crossing to Syria on the Damascus-Baghdad highway on Sunday.
He said he was mediating with ISIL in a "bid to spare blood and make things safer for the employees of the crossing. We are receiving positive messages from the militants."
The need to battle the Sunni insurgency has put the United States on the same side as its enemy of 35 years, Iran, which has close ties to the Shi'ite parties that came to power in Baghdad after U.S. forces toppled Saddam.
However, Iran's supreme leader made clear on Sunday that a rapprochement would not be easy.
"We are strongly opposed to U.S. and other intervention in Iraq," IRNA news agency quoted Khamenei as saying. "We don't approve of it as we believe the Iraqi government, nation and religious authorities are capable of ending the sedition."
Some Iraqi analysts in Baghdad interpreted Khamenei's comments as a warning to the United States to stay out of the process of selecting any successor to Maliki. (Additional by Suleiman al-Khalidi in Amman, Isabel Coles in Arbil and Phil Stewart in Washington; Writing by Oliver Holmes and Will Dunham; Editing by Peter Graff, Alastair Macdonald, Philippa Fletcher and Mohammad Zargham)
Our Standards: The Thomson Reuters Trust Principles.