A federal appeals court yesterday said that Charles B. Lankford, a former Democratic candidate for Fairfax County sheriff convicted in 1978 of sexual offenses against a teen-age girl, should get a new trial because he was not properly defended against the charges.

The ruling by the 4th U.S. Circuit Court of Appeals upheld a lower court decision ordering the new trial. Lankford, 59, came to Northern Virginia in 1968 after he was paroled from prison and later became a well-known advocate of prison reform through his work with inmates.

Lankford, who lost the sheriff's race in 1975, was employed as a cook at the Fairfax County jail when he was charged with the three counts of sodomy, convicted and sentenced to 20 years in prison.

Lankford went to federal court to challenge his conviction. In 1982, U.S. District Court Judge James C. Turk ordered a new trial and Lankford was released. He is now living in Fairfax County, according to his lawyers.

In its opinion yesterday, the federal appeals court in Richmond singled out the defense's failure to call any character witnesses on Lankford's behalf and to challenge the circumstantial nature of the victim's charges.

"Save for his own contradiction of (the girl's) testimony, Lankford was left defenseless," the court wrote. "He was without the cloak of respectability his good work since 1968 had earned him, and without the aid of good reputation for truthfulness he had acquired."

Among the witnesses who had been ready to testify for Lankford but were never called were a congressman, a high official in the State Department, a program director in the Department of Education and a church pastor, court records showed.

Fairfax attorney William T. Shannon, who had defended Lankford in the case, yesterday had no comment on the court's ruling.

Lankford, who had served 20 years in prisons around the country before his conviction in Fairfax County, became a local celebrity in the 1970s when he spoke out on the need for community services for prisoners and their families. Lankford was first arrested at age 19 when he was AWOL from the Army and went on to serve sentences for writing bad checks, bank robbery and attempted escape.

In Fairfax County he worked as youth counselor and later as director of Offender Aid and Restoration for the county. Acting on a request from the Fairfax County Board of Supervisors in 1972, then Gov. Linwood Holton restored Lankford's right to vote, which under Virginia law is automatically revoked for criminal convictions.

The appeals court yesterday also criticized Lankford's defense attorney for failing to question jurors about their potential biases in the case and for not asking the judge to tell the jury that lesser charges might be appropriate. In the end, the court said, "The case boiled down to a swearing contest between (the victim) and Lankford."

New York lawyer Alan Levine, who represented Lankford in appeals court, said his client is "confident he will be acquitted if his case goes to trial again." Barring further appeals by the state, a new trial would have to be ordered within 30 days, Levine said.