Police used rubber bullets and tear gas on Thursday when supporters of the declared winner, Violeta Menijavar, approached a hotel in San Salvador where the final results were being declared.
The election tribunal said Menjivar, of the left-wing former guerrilla Farabundo Marti National Liberation Front (FMLN), won the election by only 59 votes. Menjivar had 64,881 votes to 64,822 for Rodrigo Samayoa of the right-wing ruling Arena party.
Samayoa's supporters shouted "fraud" when the results were announced at the hotel, which the police had fortified with metal fences.
Tension has been high in San Salvador since Arena held off significant FMLN advances in mid-term elections last week.
Arena has won four successive presidential elections in San Salvador with current incumbent Antonio Saca becoming president in 2004.
Long the second-largest party, the FMLN had hoped to continue a trend of victories for left-wing movements in countries such as Brazil, Venezuela and Bolivia by winning the congressional vote on Sunday.
But with most votes counted, Arena had won 34 seats and the FMLN 32.
The tight result comes after recent closely fought electoral contests in Haiti and Costa Rica and developments will be watched in Washington.
The FMLN hoped to continue a
regional left-wing revival
El Salvador is perhaps the closest US ally in Latin America, with several hundred troops in Iraq.
It was the first country to sign the Central American Free Trade Agreement, while other states held out.
The FMLN fought a series of US-backed right-wing governments in a 12-year civil war that killed about 75,000 people before peace accords were signed in 1992. It then disarmed and formed a political party but it still opposes closer ties with Washington.