* Anti-aircraft gunfire and explosions heard near Benghazi
* Government set deadline for rebels to end oil blockade
* Nascent army takes on experienced militia (Adds details on wounded)
By Ayman al-Warfalli
BENGHAZI, Libya, March 22 (Reuters) - Libyan rebels occupying oil ports clashed with troops on Saturday when they attacked an army base, wounding 16 people before tribal leaders brokered an end to the fighting, local residents and a state news agency said.
Anti-aircraft gunfire and explosions were heard late at night and again after dawn on Saturday in Ajdabiya, the hometown of rebel leader Ibrahim Jathran, whose fighters seized three ports in summer to demand a greater share in Libya's oil wealth.
LANA state news agency said tribal community leaders helped stop the fighting later on Saturday between the rebels and Libyan soldiers, who were preparing for a possible military offensive to break the blockade that has slashed vital oil exports.
But the agency reported 16 people were wounded in the violence.
The clashes broke out just hours before the return to Libya of an oil tanker seized last Sunday by U.S. commandos in the Mediterranean after it had loaded crude at one of the ports Jathran's men have occupied.
The Morning Glory, once a North Korean-flagged vessel, was expected to arrive on Saturday in Libya under U.S. Navy escort and dock at Zawiya, one of the country's key ports under government control.
The struggle for control of Libya's vital petroleum resources is one of the challenges facing the weak central government, which has been unable to secure the North African country three years after the fall of Muammar Gaddafi.
Brigades of former anti-Gaddafi rebels and militias refuse to disarm and often use armed force or control over oil facilities to make demands on a state whose national army is still in training.
Tripoli's central government gave Jathran a two-week deadline on March 12 to end his port blockade or face a military assault, though analysts say Libya's nascent armed forces may struggle to carry out that threat.
Jathran's self-declared Cyrenaica government is demanding more autonomy for his eastern region and a share of oil revenues. Attempts to broker a deal between the federalists and the central government have so far failed.
After months of threats, Jathran's federalist gunmen managed to load crude onto the Morning Glory tanker. The ship left port and escaped Libya's navy, embarrassing Tripoli's government and prompting parliament to sack Prime Minister Ali Zeidan.
The seizure of the Morning Glory tanker in international waters was a rare boost for Tripoli's government, which has struggled to end the standoff that has cost the state more than $7 billion in lost oil revenue.
The three ports account for around 700,000 barrels per day of Libya's oil export capacity, or around half of its total petroleum shipments.
The town where Saturday's battle broke out, Ajdabiya, is divided between Jathran supporters and those who fear his oil blockade will lead to the collapse of the state.
But any major assault on the three ports may bolster support for Jathran's cause for a federalist state, allowing his eastern region more say in controlling its own affairs and spending local oil revenues.
Tripoli's government is also stymied by infighting among Islamists, secular parties and tribes that has delayed the country's transition to democracy since the fall of Gaddafi whose one-man rule left few state institutions.
Western governments, which supported NATO's air strikes to help the 2011 anti-Gaddafi rebellion, are training the country's armed forces and pressing the factions to reach a political settlement to assure more stability. (Additional reporting by Ulf Laessing; Writing by Patrick Markey; Editing by Tom Heneghan/Jeremy Gaunt)