NAIROBI, Kenya (AP) _ Ethiopian government and Eritrean rebel negotiators shook hands today on an agreement to hold formal peace talks, then came out fighting in a display that bodes ill for future negotiations.

At a news conference ending nearly three weeks of preliminary talks, the two sides disagreed on the exact meaning of their agreement and accused each other of foot-dragging and misrepresentations.

A weary former President Jimmy Carter, who mediated the negotiations, sat between the Ethiopian and Eritrean representatives as they exchanged accusations and commented: ''I've heard this kind of talk for 20 days.''

But Carter, while cautioning that he was ''not naive enough to predict certain success,'' said he was ''more optimistic than I have been at any time'' that the sides could find an end the 28-year-old war between the government and Eritreans fighting to create a separate homeland in the north.

The preliminary negotiations, which began in Atlanta in September and resumed in Nairobi on Nov. 20, ended with no agreement on a date or place for the main peace talks.

They also ended with the Eritreans accusing Ethiopia's Marxist government of obstructing the talks and contesting Carter's statement that the United Nations had declined to act as an observer in further talks.

''During the Atlanta and Nairobi talks in general, and last week in particular, the Ethiopian regime, some of its allies and certain individuals have resorted to lies, blackmail and sinister manipulations to obstruct the participation of the U.N. as an observer,'' said Alamin Mohamed Saiyed, the chief Eritrean negotiator.

Alamin insisted that the United Nations had not rejected an invitation to act as an observer in the main talks, although Carter said Secretary-General Javier Perez de Cuellar had turned down the offer in a telephone conversation Friday.

Alamin also took issue with an informal comment by Carter following his reading of the closing communique. The former president said observers chosen for the main talks ''shall witness all negotiating sessions without directly participating in the discussions.''

The Eritrean negotiator said ''mediation cannot be limited to the co- chairmen'' and noted that the role of observers was not spelled out in the joint communique. Carter conceded that ''there is some disagreement about the role to be played by observers.''

Alamin also said the government delegation had refused to discuss a drought in northern Ethiopia that he said threatens 1.5 million people with starvation in Eritrea alone.

The United Nations has estimated that up to 4 million people risk starvation in Eritrea and three other northern Ethiopian provinces, Tigre, Wollo and Gonder. The government has disputed that forecast.

The Eritrean rebels took up arms against the government in 1961 in an attempt to gain independence for Ethiopia's northernmost province, a former Italian colony that was federated with Ethiopia under a U.N. mandate in 1952.

The war and associated famines are estimated to have claimed more than 1 million lives.