* Two eastern ports to reopen on Sunday
* Further talks planned to reopen two larger ports
* Rebels want more autonomy, bigger share of oil wealth (Adds rebel comment, background)
By Ulf Laessing and Ayman al-Warfalli
TRIPOLI/BENGHAZI, Libya April 6 (Reuters) - Libyan rebels occupying four eastern oil ports agreed with the government on Sunday to end their eight-month petroleum blockade, which has cost the North African state billions in lost revenues.
Zueitina and Hariga ports, held by federalist rebels demanding more autonomy from Tripoli, will open immediately while the larger ports, Ras Lanuf and Es Sider, will be freed in two to four weeks after more talks, the government said.
Ending the oil port standoff will be a major advance for Libya's fragile government, which has struggled to impose its authority over an unruly nation still in flux nearly three years after the fall of Muammar Gaddafi.
"The ports Zueitina and Hariga will be handed over to the state with the signature of this agreement. The protesters are banned from returning or obstructing work at the ports," Justice Minister Salah al-Marghani said, reading out the agreement.
He said the two larger ports will be reopened in no more than four weeks, after more discussions with the rebels.
A rebel spokesman confirmed the agreement over the immediate reopening of the two smaller ports, but said more talks were needed to reach a breakthrough on the two remaining terminals, which are among Libya's most important.
Neither side commented on what rebel demands still needed to be negotiated with the government, leaving room for possible delays in reopening the larger ports.
Zueitina and Hariga ports account for around 200,000 barrels per day of export capacity, while the larger ports previously shipped around 500,000 bpd of Libya's crude.
Storage tanks are full at the ports, and loading the crude will be straightforward. But getting the tanks resupplied from oilfields will take time.
The reopening of the eastern oil ports could bump up Libya's output from around 150,000 bpd, but nowhere near the 1.4 million bpd it produced before last summer.
Disputes over Libya's oil resources underscore how weak the government is to confront brigades of former rebels and militias who refused to disarm after Gaddafi's fall and often use their military muscle to strong-arm the state.
With its national armed forces still in training, Tripoli's government often finds itself at the mercy of rival militias who are loosely allied with competing political factions in the country's parliament.
Rebel leader Ibrahim Jathran, who seized three of the ports with thousands of his troops, is a former anti-Gaddafi fighter, who later become head of a state-run oil facilities guard before he turned against Tripoli.
Hariga port was closed by another group of federalist protesters who sympathized with Jathran's cause.
Jathran's movement set up its own self-declared federal government in the east, where many feel they have long been neglected by Tripoli. They made three key demands on the government, including a system to share oil revenues, a probe of corruption and a committee to oversee oil exports.
The minister said the agreement calls for all charges to be dropped against Jathran's oil protection force, and for them to receive their oil guard salary payments according to the law.
A committee would be formed to investigate financial and administration corruption since Libya's liberation from Gaddafi, one of the demands made by Jathran's movement.
But the one-page agreement did not mention the rebels' other key demands - more autonomy and a greater share of oil revenue for their eastern region, known as Cyrenaica, one of Libya's three regions before Gaddafi.
The shutdown has cost the state more than $7 billion in lost oil revenues.
Support had been waning for Jathran's protest in the east, where divisions had begun to emerge over whether to continue the blockade.
Talks to end the standoff advanced after the federalist rebels last month managed to load crude onto a tanker at Es Sider and forced it out to sea in an attempt to export the cargo.
U.S. commandos later boarded the formerly North Korean-flagged vessel in international waters and returned it to Libya, in a major blow to the federalists' plan to bypass Tripoli and sell oil independently on the global market. (Additional reporting by Feras Bosalum; Writing by Patrick Markey; Editing by Gareth Jones, Mohammad Zargham and Paul Simao)