President Reagan, in seclusion during most of the last five weeks, returned to the limelight tonight with a speech in which he defended major administration initiatives and said that one of his "proudest accomplishments" was preservation of democracy in El Salvador.

In his first speech outside the White House since his surgery for colon cancer on July 13, the president appeared in good health and high spirits as he gave a 17-minute speech, interspersed with typical one-liners, at a $1,000-a-plate Republican fund-raising dinner.

Reagan joked about the operation in which a cancerous tumor was removed from his colon. He said he had received many cards and letters, including one that said, "I was very disappointed to hear that the doctors took two feet out of your inner workings. How did those two feet get in there?"

But the president was serious, as usual, when he discussed Central America. "When we first got to Washington, the question on everyone's lips was, 'Will El Salvador fall to the communists?' " Reagan said. "Today the question is, 'Will democracy win in Nicaragua?' And tomorrow the question will be -- how soon?

"We have held firm," Reagan continued. "We will continue to do what needs to be done to protect our country's security and help the people of Central America build free, prosperous and democratic countries."

Reagan's speech tonight attracted more attention for how he looked and sounded than for what he said.

The president has been out of public view most of the time since he returned to the White House on July 20, after a week in the hospital. He held a state dinner in the White House for Chinese President Li Xiannian the following week and on Aug. 5 held a news conference around his desk in the Oval Office that was limited to a handful of reporters.

Reagan has been virtually invisible since he arrived in California on Aug. 11 for a 23-day vacation, most of it spent at his mountaintop retreat called Rancho del Cielo in the Santa Ynez Mountains near Santa Barbara.

When the president and First Lady Nancy Reagan traveled by motorcade Wednesday night to the wealthy Bel Air section of Los Angeles and a dinner hosted by retired Northrop Corp. executive Tom Jones, photographers and onlookers crowded around for a glimpse of the Reagans leaving their $3,000-a-night suite in the Century Plaza Hotel. The president, looking fit, waved to reporters but answered no questions.

Tonight, Reagan faced an audience of wealthy Republicans, including a number of contributors who have supported him since he first ran for governor of California in 1966.

Reagan used the occasion to point out the difference between the GOP of 20 years ago, which attracted few young people, and the party today, which he said young people "will continue supporting . . . as long as we can offer the way to a better future."

In a line that did not seem to appreciably amuse his middle-aged audience, the president said he "used to say that the only young people [going to GOP meetings] looked like they couldn't join anything else."

Reagan appealed tonight for party harmony in 1986 when Republicans attempt to unseat Democratic Sen. Alan Cranston, whom they consider vulnerable.

"Have a spirited primary, but don't campaign against each other," Reagan urged. "Campaign against the incumbent and then stand united behind our party's choice."

During his brief speech, the president defended his tax-overhaul proposal, calling it a choice between "the special interest and the general interest." He said he would launch a major campaign for the plan this fall and would "take our case directly to the people."

He also defended his Strategic Defense Initiative, commonly known as "Star Wars," against accusations that it would cost too much and wouldn't work.

"We keep hearing from self-declared experts that our SDI concept is unfeasible and a waste of money," Reagan said. "Well, if that's true, why are the Soviets so upset about it? As a matter of fact, why are they investing so many rubles of their own in the same technologies?"

Reagan said SDI would put in place "an antinuclear shield" in which "our success will be measured by the number of people we can save, not destroy."

He made no mention of any willingness to scale down SDI and keep it purely as a research proposal if the Soviets would agree to cut back on deployment of new offensive weapons. Some administration officials have suggested that limiting SDI in the laboratory in return for Soviet reductions in offensive weapons would be a beneficial tradeoff for both superpowers.

In one passage of his speech the president appeared to be answering critics who have claimed that the administration is running low on energy by saying, "When we get back to Washington, it's going to be full steam ahead."

The Reagans are scheduled to return to Rancho del Cielo at midday Friday and remain there until Labor Day, when the president is to return to Washington.