James P. Moran Jr., who resigned as Alexandria vice mayor last June after pleading no contest to a conflict-of-interest charge, easily defeated five-term mayor and former colleague Charles E. Beatley yesterday after a bitter campaign.

Democrats retained control of the City Council, although Democratic incumbent Donald C. Casey was defeated.

Moran, a 39-year-old stockbroker who served on the council for nine years, received 51.2 percent of the vote, according to an unofficial tally, to Beatley's 39.8 percent, while a third candidate, independent John D. Williams III, got 9 percent. Moran won 25 of the city's 32 voting precincts.

The mayor is elected for a three-year term and paid $12,500 a year. Moran, a Democrat who ran as an independent against Democrat Beatley, will be sworn in July 1.

"I guess I should give my apologies to the media in advance," Moran said last night, "because there aren't going to be many stories coming out of here in the next three years." He was referring to the past year of controversy and turmoil in city government that kept Alexandria in the headlines.

Moran had tears in his eyes as he worked his way to the podium at the Ramada Inn through hundreds of cheering, applauding supporters at last night's victory celebration. "When this all started, few of us believed I had any future in politics," he said.

Perhaps because Beatley and Moran were once considered patron and protege, personal attacks overshadowed all issues during the campaign.

Their friendship dissolved abruptly when Beatley forced Moran's resignation last year.

Moran, who broke with the Democratic Party in March to challenge Beatley as an independent, called Beatley a "sleaze" during a campaign appearance at an elementary school fair on Saturday. Moran said Beatley was "making too much" of the misdemeanor conflict-of-interest charge filed against him after he cast a City Council vote on a parking lot matter that involved a personal business partner.

Beatley, in turn, hammered away at Moran's credibility, labeling him the "the darling of the developers" and saying at every campaign stop that Moran doesn't deserve the public's trust after "his brush with the law."

Beatley congratulated Moran at the Ramada Inn victory party, then told a group of his supporters gathered at one of the unfinished new office complexes in Old Town: "I can't say I'm here in circumstances I'd like to be. But I'm philosophical about things. I wouldn't do things any different. We were just outgunned in more ways than one."

Beatley, who initially retired from politics in 1976 but regained the mayor's office three years later, said he will stay close to Alexandria politics, but not as a candidate.

Moran's victory was seen by Democrats yesterday as a backlash against the handling of allegations made against Public Safety Director Charles T. Strobel earlier this year, and testimony to the former vice mayor's appeal.

Beatley and City Council member Casey pressed hard for a city inquiry into allegations that Strobel inappropriately halted a 1984 police cocaine investigation. When Circuit Court Judge Donald H. Kent impaneled a special grand jury to investigate the matter, Beatley demanded that Strobel be put on administrative leave pending completion of the jury's review.

The city manager at the time, Douglas Harman, refused to place Strobel on leave and, after exchanging sharp words with Beatley, the popular manager left Alexandria to head the city government in Fort Worth. Even though Harman said he would have accepted his new job if the Strobel controversy had never arisen, many Alexandrians blamed Beatley for Harman's hasty and sour departure.

But the harshest blow against Beatley came from the grand jury. After hearing 32 witnesses, it issued a report Feb. 27 that said the allegations against Strobel were "the callous, politically motivated activities of certain members of the Alexandria City Council."

Although unnamed, Beatley and Casey were clearly the targets of the critical language in the report.

"There is a perception that Beatley forced Harman out," said Susan B. Kellom, a strong Beatley supporter. Kellom said she believed that the grand jury controversy and lawsuits Strobel filed against the city over the matter wounded Beatley considerably.

Until two months ago, the mayor was sailing into his sixth term unopposed. Moran, sensing that Beatley was in political trouble for the first time in his long and lustrous political career, told Beatley that unless he publicly apologized to Strobel and Harman, the former vice mayor would seek his job.

After Moran withdrew from the City Council race to challenge the mayor, independent John D. Williams III, the president of the Alexandria Taxpayers Alliance, became the third mayoral candidate. Moran's campaign amassed more than $40,000 in campaign funds and 2,000 active volunteers. Beatley ran a relatively low-key campaign on which he spent $14,000.

In the City Council elections, all three Republican incumbents, Margaret B. Inman, Carlyle C. Ring and Robert L. Calhoun, were reelected. The top vote getter, Inman, automatically takes over the ceremonial role of vice mayor. Democratic incumbents Lionel R. Hope and Patricia S. Ticer also were reelected, with Democratic newcomer Del Pepper, a 47-year-old former mayoral aide, replacing Casey. The Democratic majority is completed by Moran as mayor. Although he ran as an independent since Beatley had already gotten the Democratic endorsement, he has said, "I will always be a Democrat."