SAN JOSE, Costa Rica (AP) _ Salvadoran government and guerrilla negotiators ended a week of talks at loggerheads on an armed forces overhaul, but hopeful a human rights accord reached Thursday will keep up the momentum toward peace.

The two sides reached agreement on a United Nations role to seek greater respect for basic rights at a 20-hour session that extended the Costa Rican meeting by a day. It was the first agreement produced in three rounds of talks since May.

Representatives of President Alfredo Cristiani's rightist government and rebels of the leftist Farabundo Marti National Liberation Front, or FMLN, had fretted that a third round with no progress would badly damage the effort to end 10 years of civil war. The war has killed about 72,000 people and displaced nearly one-fifth of El Salvador's population of 5.3 million.

U.N. mediator Alvaro DeSoto said the rights accord ''without doubt helps clear the way for progress on other items of the agenda.''

The U.N. mission to be established under the accord will be headed by an appointee of Secretary-General Javier Perez de Cuellar. It will comprise ''as many agents as are necessary.''

''The mission will enjoy broad powers to adopt any initiative it deems appropriate for the promotion and defense of human rights,'' said the document.

Last May, it was agreed that overhaul of the armed forces would lead the agenda, and the fruitless June round dealt almost exclusively with that topic.

Early in the Costa Rican session it became obvious that differences on the future role of the military remained vast. The guerrillas said that on some matters, the chasm had widened.

International watchdog agencies, the United Nations, the Organization of American States, and the U.S. Congress are among organizations that have chronicled flagrant and systematic abuse of fundamental rights on a huge scale in El Salvador during the past decade.

The armed forces and military-linked death squads are blamed for the murder of up to 30,000 suspected leftists. Torture of political detainees by security forces was routine for years, according to such organizations.

The United Nations said abuses continue, but that the government's rights record had improved in recent years.

The world body condemned rebels for assassinating eight mayors in 1988 and for later killing other non-combatants.

Justice Minister Oscar Santamaria, the chief government delegate, said of Thursday's human rights agreement, ''We're enormously satisfied. This is a very meaningful advance.''

Guerrilla commander Schafik Handal, who leads rebel negotiators, agreed that the document ''is an accord of great value.''

But he cautioned that the military overhaul issue remains, and is the key to the quest for peace.

''This (human rights) accord will not mean a great deal unless we advance in the field of demilitarization of Salvadoran society,'' he said.

The insurgents carried out a huge three-week offensive last November and say they are ready to launch another major push. Handal refused to say if the progress made here reduced the likelihood of an offensive in coming weeks, but other guerrilla sources said chances for an imminent offensive were lessened.

Though El Salvador has held periodic elections since 1982 and moved to consolidate some democratic institutions, the military retains great power.

A joint communique said the issue would receive ''priority consideration'' at the next round, set for Aug. 17-22 in San Jose.

It said the U.N. human-rights monitoring mission will be free to document and denounce rights violations; conduct unrestricted interviews with all people; make recommendations to both the government and guerrillas; and publish its reports, conclusions and recommendations.

The mission will begin work as soon as a cease-fire is agreed. Its original mandate is for a year, subject to extension.

Both sides say they hope to agree to a cease-fire by mid-September.

The main sticking point in peace talks appears to be the rebel demand for a purge of the worst rights abusers and corrupt officers from the high command. The government and armed forces contend a purge would violate the ''institutionality'' of the military.