Rejecting the pleas of civil rights groups, Virginia Gov. Charles S. Robb today denied a pardon to a man sentenced in 1974 to 40 years in prison for the sale and possession of nine ounces of marijuana. Instead, the governor cut the sentence for Roger Trenton Davis to 20 years, two 10-year terms to run consecutively.

The reduced term followed the recommendation of Robb's parole advisers, who said that 20 years is the "maximum allowable under current Virginia law." Davis, a black man from a rural southwestern county, will be eligible for parole in July 1984.

Davis had been free for five years while he appealed his original sentence to the Supreme Court as "cruel and unusual punishment." He returned to prison shortly after the decision.

The governor's action stunned civil rights leaders who had launched a major letter-writing campaign on behalf of the 36-year-old Davis, portraying him as a classic victim of a state judicial system they charge is permeated by racial prejudice.

"This is incredible," said Jack Gravely, state NAACP director. "This young person has paid his debt to society. But he was out to be gotten by the political and social establishment out there and they got him. The whole judicial system stinks in this state."

Chan Kendrick, state director of the American Civil Liberties Union, said he was "terribly disappointed" in Robb's decision, calling the reduction of sentence a "minimal concession" that would have been granted by any governor in the country. "He Davis has no business being in jail at all."

Some critics also contended privately there were political overtones to Robb's decision. During recent weeks, the Democratic governor has taken a number of steps sought by the state's blacks, such as his executive order denying state tax exemptions to segregated private schools. The actions may have helped head off a threatened independent Senate candidacy by black state senator L. Douglas Wilder of Richmond, but they have angered some of Robb's conservative supporters, who have threatened to desert the party during this fall's Senate race.

Robb's aides denied there were political factors in the governor's decision, insisting that it was based solely on the merits of the case and was in line with similar sentencing decisions by former Republican Gov. John N. Dalton under a 1979 state law that reduced the penalty for possession and sale of marijuana to a maximum of 10 years.

Secretary of the Commonwealth Laurie Naismith, who advised Robb on the pardon request, noted that Davis had been previously convicted for the sale of LSD before his 1973 arrest on the marijuana charges. "My feeling is when someone does have a record, they have to accept some punishment, they can't be let off scot-free," said Naismith.

The governor did not review the case until last night when Naismith and Robb discussed her recommendation. Their conversation "didn't last more 15 or 20 minutes, that was it," she said.

Davis, a tall striking man who lived in rural Wythe County, had offended local mores with his long hair, counter-culture lifestyle and his marriage to a white woman. He was arrested during a crackdown on drug use after he sold marijuana to a police informant, who was carrying a concealed microphone.

The prosecutor in the case later called his sentence too severe and three federal courts struck it down as unconstitutional in light of a national average sentence of 3 1/2 years for similar crimes. Last January a sharply divided Supreme Court upheld the initial sentence.

The NAACP's Gravely said the punishment had as much to do with the racial prejudices of Wythe County as it did with drugs. "Part of his punishment was for stepping across that invisible line," he said.