(Adds details on agreement, background, bylines)
By Ahmed Elumami and Patrick Markey
TRIPOLI, July 2 (Reuters) - Libya's acting Prime Minister Abdullah al-Thinni said the government had reached a deal with a rebel leader controlling oil ports to hand over the last two terminals and end a blockade that crippled the OPEC nation's petroleum industry.
"We have successfully reached an agreement to solve the oil crisis. We have received today Ras Lanuf and Es Sider oil ports thankfully without the use of force," Thinni said at Ras Lanuf terminal in eastern Libya. "I officially declare this is the end of the oil crisis."
Thinni said the ports had been reclaimed after an agreement with Ibrahim Jathran, whose fighters had seized the terminals almost a year ago to demand more regional autonomy.
Jathran told reporters that he had handed over the ports as a "goodwill gesture" to the new parliament, which was elected last month.
Taking back the two major eastern oil terminals could make around 500,000 more barrels a day of crude available for export, a major breakthrough for the North African state whose coffers have been hit hard by oil revenue losses.
The end of the blockade would also see a final chapter of a crisis that included failed negotiations, threats to bombard rebels and even an attempt by Jathran to dispatch an oil tanker that was later boarded on the high seas by U.S. commandos.
Disputes over Libya's vast oil resources have been among the many triggers for conflict between rival brigades of former rebels and allied political factions since civil war ended four decades of Muammar Gaddafi's one-man rule in 2011.
The announcement by Thinni and Jathran appeared to show a more solid agreement to end the oil standoff, but shipments may still face technical delays and past negotiations have been slowed by subsequent political disagreements.
World oil fell below $112 a barrel on Wednesday on a possible substantial recovery in Libyan exports.
Libya produced around 1.4 million bpd before a wave of protests, strikes and blockades reduced the output to as low as 150,000 bpd. As of Tuesday, national crude output stood at 321,000 bpd.
Jathran's rebels and their allies, who were all former state oil protection guards before their mutiny, had agreed in April to reopen the two smaller ports, Zueitina and Hariga, and then gradually free up Es Sider and Ras Lanuf.
After that deal, shipments from Zueitina were delayed because of technical damage from the blockade, while Hariga terminal loaded a tanker of crude at the end of last month.
Storage tanks at seized ports are likely full, and loading initial crude will be straightforward, but getting resupplies from oilfields may be complicated.
Separate protests have also curtailed production at some oilfields, and other groups may still target pipelines and oil facilities to make political or financial demands on a government that struggles to control many parts of the country.
Three years after the fall of Gaddafi in the NATO-backed war on his regime, Libya is far from stable, with brigades of former rebels allied with competing political factions still powerbrokers in the face of a weak state.
Over the last two years, heavily armed militias have seized ministries, attacked the congress, kidnapped diplomats, and even briefly abducted a prime minister from his hotel room to pressure the government to meet their demands.
Many of those former rebels are on the government payroll to co-opt them. Often though, their loyalties are stronger to tribe, political faction, region or rebel commander than to the nascent Libyan state.
Jathran's seizure of three major ports and the taking of a fourth by his allies since last summer clearly illustrated Libya's fragile democracy and cost Libya billions of dollars in petroleum revenue.
On Wednesday, the rebel leader blamed the former parliament, which was known as the General National Congress or GNC, for delays in handing over the oil ports.
The GNC was paralyzed by infighting among Islamist factions including a Muslim Brotherhood-linked Justice and Construction Party, a more liberal-leaning National Forces Alliance movement and scores of independents. (Reporting by Ahmed Elumami; Writing by Patrick Markey; Editing by Toni Reinhold)