Rebel Army units ousted President Carlos Humberto Romero today and said that a joint military-civilian junta would run the country, diplomatic sources reported.

A Gutemalan aircraft came to pick up the president and his family, but reports that he had left the country could not be confirmed.

A communique from the rebels, read over state radio, said Romero was overthrown to "restore constitutional order" in the Central American country.

Political violence has escalated dramatically in recent months, as the military-backed government showed signs of internal weakness and leftist Salvadoran guerrillas gained encouragement from the Sandinista overthrow of Anastasio Somoza in neighboring Nicaragua.

The State Department -- worried about a "domino effect" in Central America -- had launched a concerted diplomatic effort aimed at heading off a Nicaragua-like revolution, and in early August tried to persuade Romero to advance presidential elections scheduled for 1982.

There have been repeated rumors that a coup was being planned within the Army, in which Romero is a general. It remains unclear whether today's coup came from right-wing extremists who objected to Romero's recent liberalizing reforms, or from younger officers closer to the political center who felt that only a sharp cutback in government repression would hold off a leftist-led general insurrection.

A spokesman for the rebels said a three-man junta with at least one civilian member would be named to run the country. Shortly afterward, five names were made public, but a later announcement named two officers --Col. Adolfo Arnoldo Majano, 41, and Col. Jaime Abdul Gutierrez -- as interim leaders of the country.

The coup apparently began early today when rebel units seized four key military barracks.

Some shooting was reported in late morning at the barracks in Chalatenango, 30 miles northeast of here, and in Sonsonate, 38 miles to the west, an unidentified Army captain was reported killed.

A spokesman for the rebels said the insurgents also seized barracks in San Miguel, 100 miles east of San Salvador, and just outside the capital in San Carlos, site of the nation's largest military installation. There were unconfirmed reports of shooting in some areas of San Salvador.

Recent leftist violence in El Salvador brought a response from rigntist groups, some reported to include off-duty policemen, who have been attacking and killing leftists.

El Salvador has a 47-year history of military or military-backed governments. The country of 4.5 million -- sandwiched between Guatemala and Honduras along the Pacific Ocean -- is sharply polarized between right and left, rich and poor, and there has been virtually no dialogue between the government and the more radical opposition.

There are a half dozen leftist groups, including several radical ones. The largest leftist group is the Popular Revolutionary Bloc, which in May staged nonviolent occupations of the Metropolitan Cathedral and three foreign embassies in the capital.

During the occupations, government troops fired into crowds of milling demonstrators outside the church, killing 23 persons, and two weeks later fired on protesters outside the Venezuelan Embassy, killing 14 persons. l

Since then, violent attacks by both left and right have been occurring almost weekly. Besides attacking and killing government figures, the more radical leftist groups have been kidnaping foreign businessmen for multimillion dollar ransoms, presumably used to support their movements.