Charles Lewis, whom federal investigators credit with providing the first credible evidence of Mayor Marion Barry's alleged drug possession, was sentenced to five years' probation by a judge in the U.S. Virgin Islands yesterday and ordered to perform 1,000 hours of community service.

U.S. District Judge Stanley S. Brotman, who was assigned to St. Thomas temporarily from his home district in New Jersey, said he had given long consideration to Lewis's sentence and was departing reluctantly from federal sentencing guidelines that called for a prison sentence of up to 51 months.

The judge said he thought it was important to impose a prison term as a deterrent to others who might violate drug laws.

Washington attorney Mark L. Shaffer, who represented Lewis in his drug case here, urged Brotman not to impose an additional prison term on Lewis, who in June completed a 13-month sentence for a drug conviction here. U.S. prosecutors on Wednesday urged "favorable consideration" for Lewis.

"It hurts me to do it," Brotman said. "I feel you should serve some time . . . . You got a break, a real break. Next time you go away, you go away forever."

"That was a close call," Shaffer said after the sentencing.

During the hearing, Brotman asked Terry Halpern, the U.S. attorney for the Virgin Islands, why Lewis should not be sent to prison. Halpern responded that Lewis had provided substantial assistance to the Barry investigation.

"What do we do for deterring {crime} and protecting the people of the Virgin Islands?" Brotman asked Halpern. "Forget about the people of Washington, D.C. They can take care of themselves."

Halpern responded, "We cannot attain our goals without the cooperation of people like Mr. Lewis . . . . We want the message to come across, 'If you cooperate with the government, we will let the court know.' "

Urging Brotman not to impose a prison sentence, Shaffer produced a letter from the FBI's Washington field office praising Lewis, saying he had been truly rehabilitated and that he was contrite.

Shaffer called Lewis more than a witness in the Barry case. He said Lewis "was a member of the government's team . . . . FBI agents and police investigators came to Mr. Lewis for advice and counsel."

Outside the courtroom, Lewis was surrounded by his family and friends.

Lewis's mother, Maria Lewis, wiped tears from her eyes as she hugged her son and thanked Shaffer and Virgin Islands lawyer Leonard B. Francis, who represented Lewis in his trial in St. Thomas.

Lewis was convicted in the Virgin Islands in April 1989 of possession and distribution of cocaine after he was arrested by FBI agents in a sting at the luxurious Frenchman's Reef Hotel at the rim of the Charlotte Amalie harbor.

After his arrest, he was indicted by a grand jury in Washington that was investigating allegations of drug use by Lewis and Barry at the Ramada Inn during December 1988. Lewis was convicted on the drug charges in the Virgin Islands in April 1989 and the next month returned to Washington, where he was held without bond.

In August 1989, he decided to cooperate with investigators. In June, Lewis was the lead witness in the two-month trial of the mayor, and he testified that he and Barry used cocaine and crack at the Ramada Inn on four days in December 1988 and at other times in the Virgin Islands in 1988 and 1986.

Barry was convicted Aug. 10 on one count of cocaine possession and acquitted on a second count. The jury was unable to reach a verdict on the remaining 12 charges, including those based on Lewis's testimony.

John H. Shaw of the Virgin Islands Daily News contributed to this report.