President Reagan today challenged the outcome of the Philippine presidential election that kept Ferdinand Marcos in power, saying that it was "marred by widespread fraud and violence perpetrated largely by the ruling party."

The president acted after Senate Foreign Relations Committee Chairman Richard G. Lugar (R-Ind.), who headed the official U.S. observer team, issued a statement charging that the balloting was so "fatally flawed" that he would "not accept the legitimacy of this vote count by the National Assembly," which is controlled by Marcos supporters.

"If there is no change in the situation, Congress will not support military assistance to the Philippines, and I agree," Lugar added in a telephone interview with The Washington Post.

Reagan stopped short of saying that Marcos should relinquish power to his challenger, Corazon Aquino. But the president dramatically departed from his previous comments on the election in a statement issued here shortly before he ended a brief vacation at his ranch northwest of here and departed on a return flight to Andrews Air Force Base.

The statement said that the fraud and violence "was so extreme that the election's credibility has been called into question both within the Philippines and the United States." In previous comments on the election, most recently at his news conference last Tuesday, Reagan withheld direct criticism of Marcos and suggested that fraud may have occurred "on both sides."

But officials said that, within a day after he made that statement, reports from intelligence and diplomatic sources made it unmistakably clear that the Marcos forces were winning the election by fraudulent means. A high-level U.S. analysis made available to the president concluded that Aquino would have won the election if the results had been fairly tabulated.

One U.S. assessment was a CIA report earlier this week that concluded, according to official sources in Washington, that under reasonable assumptions about the behavior of uncommitted voters, Aquino should have won a 58 percent majority. However, a CIA official noted that the analysis was "hedged," and a senior administration official added that it was a "speculative extrapolation of Philippines voter data."

A senior White House official said that the purpose of the statement issued today was to keep the United States "positively involved" in the Philippines, "to help, to look for a constructive role."

Before the statement was issued, the official said, Reagan talked by telephone from his mountaintop ranch with several key advisers, including national security affairs adviser John M. Poindexter in Santa Barbara, Secretary of State George P. Shultz in Washington and White House chief of staff Donald T. Regan, on vacation in Florida.

Officials said all advisers urged him to make a further statement on the election. The president also was aware that Lugar had condemned the widespread fraud.

The official said the statement was prepared before Roman Catholic bishops in the Philippines condemned the election. The White House withheld the statement until the Philippines National Assembly certified Marcos as the winner.

The statement said that the election was marked by "heartening evidence of the continuing commitment of the Filipino people to the democratic process, and the furtherance of a two-party system which should strenthen that process in the future.

"Although our observation delegation has not yet completed its work, it has already become evident, sadly, that the elections were marred by widespread fraud and violence perpetrated largely by the ruling party," the statement continued.

"It is imperative that all responsible Filipinos seek peaceful ways to effect stability within their society and to avoid violence which would benefit only those who wish to see an end to democracy. Both sides must work together to make those reforms which are needed to ensure a stable democracy, a truly professional military and healthy economy.

"Our hearts go out to the people of the Philippines," the statement concluded. "They are at a major crossroads in their history . . . . There are no easy answers. And in the last analysis, they will have to find the solutions themselves. But they will have our help -- in any way we can."

The senior official who briefed reporters here was asked whether the White House considered Marcos "the government" and whether the United States would continue to work with him. The official replied that Philip C. Habib, the special envoy Reagan has sent to the Philippines, would "work with everybody" and "deal with the Philippine body politic."

The statement issued today, although it did not go far enough for some State Department officials, was said to represent a consensus by State, the Defense Department, the Central Intelligence Agency and the National Security Council.

An official said to do otherwise would "taint" the Reagan administration by inferentially approving the process by which Marcos kept himself in power.

Lugar said that if the administration is to win congressional support for continued aid, there must be "some reordering" of the political power structure in the Philippines. But, while stressing there would have to be "considerable change," Lugar said he did not want to be specific at this time.