STOCKHOLM, Sweden (AP) _ A woman testified today that she saw the man accused of killing Prime Minister Olof Palme shouting in a drunken rage in September and extolling the leader's death.

The witness, Sigrid Lovisa Malm, testifed that Carl Gustaf Christer Pettersson said that if Palme had not been dead already, he should be killed.

She said Pettersson also may have said he killed Palme, but she could not make out his exact words.

Palme, Sweden's four-term prime minister, was killed Feb. 28, 1986, and his wife, Lisbeth, was wounded when they were attacked by a gunman as they left a movie theater.

Pettersson was arrested in December.

Mrs. Malm, 64, testified that she saw Pettersson at a suburban train station, ranting against Palme and praising his death.

She said Pettersson shouted that ''I'' or ''someone'' shot Palme. She said she was frightened by his drunken aggressiveness and could not distinquish whether he was saying ''jag,'' the Swedish word for ''I,'' or ''man,'' which means ''someone.''

The prosecution also produced a witness to contradict Pettersson's alibi that he spent the evening at a gambling club and then went home.

Reinhold Julius Jansson, 60, disputed Pettersson's claim that Pettersson, Jansson and Lena Akerlund, met at the club a few hours before Palme was shot.

Jansson said, ''I can't remember meeting either Christer or Lena that day.'' Asked if he thought Pettersson was lying, Jansson said: ''Maybe he got the day wrong.''

Miss Akerlund, who also testified, said she did not trust her memory because, ''I was constantly on drugs mixed with booze.''

Pettersson initially was a suspect in the slaying but was not charged until this year because of a bungled investigation in which authorities pursued a theory that the killing was the result of an international conspiracy.

Palme's widow is to testify on Monday after the court granted a list of her conditions, including the exclusion of Pettersson from the courtroom. The court refused, however, to hear her testimony in a session closed to the public.