For 30 years, Gaston Defferre has been winning elections in this turbulent port city by presenting himself as "the rampart against communism." Today, at 72, he is fighting one of the toughest battles of his political career with wholehearted Communist support.

That helps explain why, when the votes are counted tonight in the first round of the French municipal elections, more attention is going to be devoted to Marseilles than any other town in the country.

Defferre is also interior minister, a key figure in the 21-month-old left-wing experiment of his fellow Socialist, President Francois Mitterrand.

As mayor of Marseilles for five consecutive terms, Defferre is the last of France's old-style city bosses, with an electoral machine that has been compared to that of the late mayor Richard J. Daley in Chicago.

There is no city that the French right would more dearly love to win than Marseilles and no mayor they would more like to topple than Defferre.

For many Frenchmen, Defferre--a resistance leader in World War II--is Marseilles.

In 1977, a popular French news magazine began an article on France's second city, after Paris, thus: "Republics and presidents come and go, but Gaston Defferre remains. He is as immovable as Notre Dame de la Garde," the huge basilica that dominates the skyline of the old port.

Six years later there is a sense that, whatever the outcome of this election, the Defferre era is drawing to a close--the twilight years of a patriarch struggling to assert his authority over a large and unruly family. The political habits of a generation are coming unstuck--and the jostling to replace the old man has begun.

The presence of the Communists on Defferre's election list represents just one of the cracks in the political mold that he set in place after World War II.

In recent months, his reputation for good government has been tarnished by a corruption scandal. The city's economy, which is heavily biased toward the port, is decaying. And the "old guard" of resistance fighters who made up the Socialists' invincible electoral machine is being ruthlessly pushed aside by ambitious younger men.

They make an odd couple in some ways, Marseilles and Defferre. An ethnic melting pot with a population of more than 900,000, Marseilles is noisy, easy-going and colorful. As a center of drug smugglers, it was the starting point for the "French connection," which was dismantled in the 1960s. More recently, it has been the scene of shootouts between rival criminal gangs.

Defferre, on the other hand, is ascetic, self-disciplined. He says he drinks only water. He has fought two duels to defend his honor (one with pistols, one with swords). A Protestant from the Cevennes mountains, he puts in 14-hour workdays and shuttles between Marseilles and Paris. He despises the local game petanque, a kind of bowling played in the dirt.

"He is a man who prefers to be feared rather than loved," explained Roland Amsellem, a former deputy mayor and the leader of the 80,000-strong Jewish community.

The coupling of Defferre and Marseilles began in 1953 when he was first elected mayor. Then, as now, the Communist Party represented the single most numerous and best organized political force in the city. In order to keep the Communists out, the professional middle classes and petty bourgeoisie voted for the Socialists under Defferre.

This coalition triumphed in all subsequent elections. In 1965, part of the Socialist Party broke away and sided with the Communists. But Defferre thrashed them just the same, using as his campaign poster a picture of a hammer and sickle superimposed on Marseilles and the slogan, "Never this."

Times have changed, however, and since May 1981 the Communists have been junior partners in the Socialist-led government in Paris. Defferre says it would have been "dishonest" to work with Communist ministers in the Cabinet and not accept Communists in the mayor's office here. Besides, like Mitterrand himself, he evidently feels that he can control them better this way.

In an interview, he illustrated this point by citing French defense policy. Communists in the government, he said, have not kept Mitterrand from endorsing the stationing of U.S. missiles in Europe to restore the nuclear equilibrium between East and West. This was farther than former president Valery Giscard d'Estaing ever went.

Asked whether the Communists had now succeeded in breaching the "rampart," he replied: "Not at all. It's all out in the open. Nothing is hidden."

The new alliance with the Communists could, however, cost Defferre some of his traditional support. This is the calculation on which the outcome of the election hangs. Will the Communist vote--steadily 30 percent of the electorate--make up his losses in the center? Or will many Communist voters stay at home rather than cast their ballots for a man who until recently was their sworn enemy?

In magnificent disregard of his age and length of time in office, Defferre has chosen to campaign under the slogan, "The new Marseilles." His political opponents have replied, "Let's change Marseilles" and "30 is enough."

Like the left, the disparate opposition groups on the right have put up a single list of candidates. Here, it is headed by Jean-Claude Gaudin, 43, a jovial history teacher who once served on the City Council under Defferre.

In comparison with earlier election brawls, the present campaign here has been good-tempered. Defferre has succeeded, however, in creating the impression that his opponent, while a nice man, is not tough and energetic enough to run such an unruly city.

He has also stung Gaudin into suing him for libel by suggesting that the opposition could be morally responsible for a run of bombing attempts in Marseilles.

The central themes of the opposition have been the high rate of immigration and the rising crime rate. Middle-class residents complain that one area of the city after another is being colonized by Arabs, who now comprise 15 percent of the population. Much of the city center around the Canabiere shopping street, once the pride of Marseilles, now resembles a North African casbah.

Defferre has sought to turn the immigration issue to his advantage by putting the blame on successive right-wing governments in Paris. His election posters proclaim: "Under the right, 20 years of savage immigration. With the left at last, a vigilant control of which the effects can be seen."

To defuse concern about security, Defferre has drafted and stationed around town hundreds of riot police. His opponents suspect they are only there for the election.

"Just watch, in two weeks they'll all be withdrawn," predicted Jacqueline Grand, a lawyer who is standing against Defferre at the head of one sector's opposition list. She says she has been attacked in the street three times and had her home broken into four times.

Being interior minister has helped Defferre, according to opponents, who allege that he has drawn up the election boundaries so as to give him a built-in advantage of five percentage points. The alleged gerrymander was described by the right-wing newspaper Le Figaro as "a masterpiece of its kind."