Five months of diplomacy by France have been rewarded by an agreement with Libya to pull the forces of both countries out of the African nation of Chad where they have been supporting opposite sides in a drawn-out civil war.
Evacuation is due to start on Sept. 25 under the agreement announced Monday in Paris. France insists it has satisfactory guarantees from the mercurial Libyan leader, Col. Muammar Qaddafi.
But given the Libyan leader's record, the question must remain open for the time being as to whether the agreement is a sign that Libya really has decided to start mending fences with the West.
The agreement was concluded during two days of negotiations in Tripoli by French Foreign Minister Claude Cheysson. France says its troops will go only when they are sure the Libyans are leaving.
As Mr. Cheysson put it after returning to Paris: ''If they stay, we stay. If they go, we go. If they return, we return.''
French officials say the geographical proximity of Libya to Chad, compared to the distance between Chad and France, is not a problem, given the speed with which French troops can be flown to Africa. The Libyan and French forces will take their weapons and equipment with them.
Unlike the Reagan administration, the government of Francois Mitterrand has always considered it worth trying to keep contact with Libya alive. This did not prevent the French sending 3,000 troops to Chad 13 months ago to support the government of President Hissene Habre against a Libyan-backed rebel group.
The French troops have concentrated on establishing and holding a strong defensive perimeter on the north edge of Habre's zone of influence in the south of the country.
There has been little actual fighting. Only one Frenchman has died in combat. He was a pilot whose aircraft was shot down. Eleven other French soldiers have been killed in accidents.
President Mitterrand saw the French presence in Chad as serving two purposes. It was proof of France's readiness to send troops to back up its treaties with former African colonies like Chad. The 3,000 French soldiers and airmen also served notice on Libya that pursuit of expansionist aims would bring it into conflict with a big European power.
But a diplomatic solution was always France's ultimate aim, and diplomats in Paris sensed a possible opening last spring when Colonel Qaddafi began to speak vaguely of withdrawal prospects. Contacts were set up. The clinching element came in August when, to everybody else's surprise, the conservative kingdom of Morocco signed a ''treaty of union'' with Chad.
President Mitterrand had talks with King Hassan of Morocco as the treaty went into effect on Sept. 1. The contents of their discussion remain a close secret.
The French foreign minister says the Moroccans did not act as a go-between in arranging the withdrawal agreement. But there is no doubt that what Mitterrand heard from Hassan convinced him it was worth trying to reach an agreement on Chad with Libya.
As a result the President decided that Cheysson should go to Tripoli on Sept. 15 and 16 to sew things up. Then a last-minute cancellation of a scheduled weekend trip by Cheysson to Washington caused misplaced speculation about a diplomatic chill between France and the US.
If it holds, the withdrawal from Chad will have two major potential consequences, apart from easing relations between France and Libya. It could open the way for a peace conference between the opposing groups in Chad.
More generally, it should affect the general outlook for relations among North African nations. At present Morocco and Libya are lined up on one side, with Algeria, Tunisia, and Mauritania on the other.
Socialist France was linked most closely with Algeria until this year. But recently France established better relations with Morocco.
President Mitterrand would like to use a lowering of tension in Chad to promote reconciliation between the two groups of nations in North Africa which are divided both by history and by a long-standing guerrilla conflict in the Sahara.
But first the French are going to have to make sure the agreement with Libya will last. Prudently, they are refusing to say for the moment when the withdrawal from Chad is due to be completed.