JOHANNESBURG, South Africa (AP) _ President Nelson Mandela was granted a divorce today, ending a 38-year marriage that survived the darkest days of apartheid but collapsed because of allegations of adultery.

In a nation where Mrs. Mandela has a political following of her own, the couple's breakup had importance beyond the family. Both were leaders in South Africa's long struggle against white minority rule.

The judge said Winnie Mandela, who contested her 77-year-old husband's divorce request, failed to counter his most serious accusations: that she had cheated on him, and that, since they separated in 1992, they have had a marriage in name only.

``On evidence which was not challenged and the reliability of which can be accepted with confidence, the plaintiff is entitled to a divorce,'' Judge Frikkie Eloff said.

``Divorce is granted.''

Mandela closed his eyes from time to time as the judge read his decision. Winnie looked down at the defense table, her face grim. They left without speaking to the dozens of reporters in the courtroom.

The couple wed in 1958 after Mandela divorced his first wife. The marriage quickly came under strain as Mandela was arrested in 1962 and imprisoned until 1990, when he was freed to negotiate an end to apartheid. He later was awarded the Nobel Peace Prize and elected president.

During his imprisonment, Mrs. Mandela, now 60, became an anti-apartheid leader in her own right, popular with the African National Congress's radical wing. But she lost influence as Mandela pushed the ANC along a moderate course.

Mandela fired her early last year as deputy minister of arts, culture, science and technology after a series of controversies.

Hundreds of South Africans gathered outside the courtroom.

``I'm disappointed with both of them,'' said Louisa Dikgale, a 26-year-old student. ``When you're separated, you can try to get back together. This is the president. He should be a role model. Everybody makes mistakes.''

The judge's decision came just minutes after Mrs. Mandela fired her lawyer, Ismail Semenya, in court. Eloff said the gesture was nothing more than an attempt to buy time, and ordered Mrs. Mandela to defend herself.

``I do not now know what to do my lord,'' Mrs. Mandela told Eloff. ``I am not the state president. I'm an ordinary person.''

Eloff insisted that Mrs. Mandela sum up, and she offered a plaintive: ``This is no ordinary case.''

A hearing to determine the divorce settlement was scheduled Wednesday. Weekend press reports claimed that Mrs. Mandela would seek about $5 million, which she says is half of Mandela's worth.

In an affidavit supporting his divorce request, Mandela said his earning were ``not of consequence,'' but did not specify a figure. His salary as president is about $142,000 a year. He also has income from a best-selling autobiography, but most of those funds go to charity.

The affidavit said Mrs. Mandela was living beyond her means, spending much more than she earns on clothing, make-up and entertainment.

The Mandelas separated in 1992 after Mrs. Mandela was convicted and fined in the kidnapping of four youths by her bodyguards. One of the youths was beaten to death.

Mandela filed for divorce last year. During his first day on the stand Monday, the president said his suspicions his wife had been unfaithful were confirmed when a newspaper editor showed him a letter.

Mandela said he recognized the handwriting of the letter, in which the writer professed love for a Johannesburg attorney named Dali Mpofu.

The letter, which was published in South African newspapers shortly after the couple separated in 1992, also linked Mpofu and Mrs. Mandela to the possible misuse of African National Congress funds.

Mrs. Mandela and Mpofu, who served on her defense team during the trial on kidnapping charges, have denied having an affair.

Before his dismissal, Semenya had taken Mandela step by step through the arrests, bannings and financial and personal difficulties Mrs. Mandela suffered during their marriage.

``She was subjected to very cruel persecution by the security police of the day,'' Mandela said from the witness stand. But he added: ``There were many women in this country who suffered far more than she did.''

After a lunch break, Semenya asked for more time to bring in witnesses who would have supported Mrs. Mandela's arguments that a smear campaign by the former white minority government contributed to the breakup of her marriage.

Eloff refused and criticized Semenya for failing to address Mandela's central arguments: that his wife had cheated on him, and that he was determined to end the marriage.

Mrs. Mandela then called Semenya to the defense table. After a whispered conversation, he announced he had been fired.

After Mandela fired her early last year as deputy minister of arts, culture, science and technology, Mrs. Mandela checked into a private clinic and was described as suffering from diabetes.

She remains a member of parliament and leads the ANC Women's League.