The United States and Ghana yesterday exchanged a Ghanaian national accused of spying on CIA agents in his homeland for a group of Ghanaians who allegedly worked with the American intelligence agency in the West African country. It was an unusual swap of alleged spies between the United States and a Third World country.

Michael A. Soussoudis, a first cousin of Ghana's leader, Flight Lt. Jerry Rawlings, was released yesterday morning to the custody of the Ghanaian ambassador to the United States, minutes after he was whisked into a closed federal courtroom and sentenced to 20 years in prison for receiving classified information from a CIA clerk who had become his lover in Africa.

The sentence was suspended on condition that Soussoudis leave the country within 24 hours, according to government sources.

A few hours later the former CIA employe, who has admitted giving classified information to Soussoudis, was sentenced to five years in prison in a dramatic hearing before another judge in the same courtroom in Alexandria.

Her lawyer charged during the hearing that the CIA knew that Sharon M. Scranage, a native of a small, rural community near Fredericksburg, Va., was targeted by Ghana's intelligence service but failed to alert her.

Amid the sobbing of nearly 40 friends and relatives, Scranage, 30, was ordered by U.S. District Court Judge Richard L. Williams to begin serving her sentence immediately.

The judge said he would recommend that Scranage be eligible for parole in 18 months. She also was sentenced to two years of probation following her release from prison and to perform 1,000 hours of community service.

In return for Soussoudis, said Justice Department spokesman John Russell, "a number of Ghanaian citizens who have been in custody and have special interest toward the U.S. have been released and their families allowed to go to other African countries." Another individual familiar with the case said nine Ghanaians who had been in custody were taken from Ghana yesterday to the neighboring country of Togo.

Yesterday's events ended an unusual spy case that began July 10 with the arrest of Soussoudis at a Holiday Inn in Northern Virginia. The FBI alleged in court papers that Scranage gave Soussoudis the identities of several CIA employes and informants in Ghana when she worked there from 1983 to May.

Last week, in a hearing in Alexandria closed by U.S. District Court Judge Claude M. Hilton on the grounds of national security, Soussoudis, 39, pleaded nolo contendere (no contest) to two counts of receiving classified information, according to government sources. Yesterday, in a second proceeding closed to the public, Hilton sentenced Soussoudis, the sources said.

U.S. marshals then drove Soussoudis, still in leg irons and handcuffs, to an undisclosed location while Ghana's ambassador to the United States, Eric Otoo, followed in his car. Soussoudis was handed over to the ambassador, who arranged for him to leave the Washington area.

Soussoudis was expected to arrive in London today, according to African sources.

The names of the Ghanaians who were being exchanged could not be learned yesterday. Four Ghanaians, including one former U.S. embassy employe, last week pleaded guilty to espionage there, and several others were under arrest.

Scranage testified publicly for the first time yesterday about her experiences in Ghana, where she worked as an "operations support assistant" for the CIA.

She said that she was given a house and "tucked away all by myself," apart from the American compound in Accra, even though she had never lived alone. She met Soussoudis on the second day in Ghana, and they began dating.

"I was in love with him," she said.

Scranage testified that she informed her CIA station chief that she was dating Soussoudis. He told her "to be careful" but did not tell her to stop dating Soussoudis, she said.

On Nov. 7, 1983, Scranage said, the station chief informed her that a high-ranking Ghanaian official had told the U.S. ambassador that "a black female in the embassy was having secret meetings with Ghanaians and that she'd better cut it out."

She said the station chief told her "to break off with Michael Soussoudis gradually" and that she tried to do this.

Brian Gettings, her lawyer, told the court that the CIA had "breached its duty" to protect Scranage "from the other side." CIA officials "knew beyond any doubt as of Nov. 7, 1983, that she'd been targeted by a Ghanaian intelligence unit and did none of the things you'd expect even from a common sense point of view," he said.

They "told her to break off the relationship, but they didn't tell her why," Gettings said. Scranage "has come to know she was used, totally used," he said.

Assistant U.S. Attorney Justin Williams said in court that Scranage was given a year of training and "sufficient information as to prepare herself for what she would find in Ghana."

A CIA spokeswoman declined to comment.

Prosecutor Williams told the court that Scranage had cooperated after her arrest, helping authorities prepare a "damage assessment." But he asked for a "substantial" sentence for the three counts to which she had pleaded guilty, which carried a maximum sentence of 30 years in prison and a $70,000 fine.

"I'm very sorry about all the damage I've done," Scranage tearfully told Judge Williams and a courtroom packed with relatives and friends from King George County. "I'm just thankful God brought me home alive," she said.

Scranage gasped as Williams imposed the five-year sentence. "I must say because you appear to be such a nice person that sentencing you is not a particularly pleasant assignment for me," the judge said.

But he said it was necessary that "a message will go out to all people who work for the CIA" that such offenses be met with "sure and certain punishment."

Calling her sentence "very light," Judge Williams ordered her to begin serving it immediately so that its "impact and signficance is brought home."