TRIPOLI, May 26 (Reuters) - Libya's new premier said on Monday his cabinet will focus on fighting militants, securing borders and building up armed forces with foreign help, and appealed to hardliners who want his government removed.

Libya is caught up in what the European Union has called its worst crisis since the 2011 civil war that ousted Muammar Gaddafi and pitched the North African country into almost constant state of upheaval and violence.

Prime Minister Ahmed Maiteeq is Libya's third prime minister since March and inherits a country in which, three years after Gaddafi's fall, brigades of former rebels are still powerbrokers over the fragile state and ally themselves with competing Islamist and anti-Islamist factions.

Maiteeq's government was approved by parliament only a week after the congress was attacked by gunmen claiming loyalty to a renegade former army general who vows to purge Islamist militants because he says the government had failed to.

"Libya is passing a very difficult time... As Libyans we were flying so high in our expectations. We should be realistic," Maiteeq told Reuters. "We should focus on our problems, and our problems now are fighting terrorism. Fighting terrorism in Libya should be helped by international society as well."

As well as thousands of former rebels loosely allied to political parties, the lack of a strong state has also let Libya become a safe haven for hardline Islamist militants who are blamed for bombings and assassinations.

Worried unrest in the OPEC oil producer may spill over into regional chaos, the United States and European Union have been helping train Libya's nascent army. But political turmoil has undermined programmes to build up an effective force.

Diplomats say Maiteeq, a hotelier and businessman partly educated in London, may seek a more technocrat cabinet, but he will struggle to rein in factions and militias whose infighting left previous governments powerless to impose any authority.

Maiteeq's government has been rejected by former General Khalifa Haftar, whose irregular forces want to fight Islamist militants and have demanded the General National Congress (GNC) parliament hand over power.

Several military units have allied with him, threatening to split regular forces and the network of competing militias, and his campaign against extremists has touched a nerve for Libyans fed up with instability.

But rival factions have rejected Haftar as trying to force a coup, and it is not clear how much of a broad anti-militant alliance the former Gaddafi ally can really muster.

"His message to Libyans to fight terrorism, to start to build our interior ministry and the Libyan police and army.. this is a very good message," Maiteeq said, in an apparent attempt at bridge-building with Haftar.

"Three years is enough to calm everyone down. Even the hardliners feel that they have to sit down together," he said when asked about the chances of bringing rival groups to the negotiating table.

But Maiteeq was more coy on which groups he considered targets for military action, and whether they included those such as Ansar al Sharia, which has been branded a terrorist group by Washington but has a network in eastern Libya.

"Our main issue is security and to bring stability to our country. I ask the international community to help," he said. "We have to sit together with the international community.. and focus on who is bringing instability to Libya."

OIL NEGOTIATIONS

Maiteeq also said he wants to continue with a deal with another former rebel who has occupied four key oil ports since summer, cutting off vital crude exports to demand more autonomy and funds for his eastern region.

The port rebel, Ibrahim Jathran agreed with Maiteeq's predecessor to steadily lift his blockade, but he has rejected the new premier as illegitimate.

"We have to see how this deal will reach, and if we reach a deadlock or the end of this deal we will try to find another," he said. "They are part of Libya, they are Libyans, we should discuss everything before moving to another solution."

But the new premier said he did not expect to have to borrow domestically or internationally to cover budget needs after the oil protests, though his government was still in the early stages of looking at financing needs.

Libya has proposed a June parliamentary election as a way to end the standoff over the congress, which has been paralyzed by splits among Islamist and anti-Islamist parties. But Maiteeq said he expected his government to stay on after the vote.

"If we are going to be realistic you need to study the time, in one month you have the election, you need another one or two months for the new parliament to start work," he said. "We are going to be there to help our country, as long as they need us." (Reporting by Patrick Markey and Ulf Laessing; Editing by Hugh Lawson)