John Bayard Anderson, for 30 years a loyal Republican and defender of the two-party system, yesterday became an independent candidate for president, insisting "I am not in this race to function as a spoiler."

Speaking in somber, reserved tones, the Illinois congressman said he was abandoning his 10-month quest for the Republican nomination "because it is now clear that I cannot attain a majority of delegates" to the GOP national convention in Detroit in July.

Anderson, who failed to win a single Republican primary this year, released the 56 delegates he had gained and returned $307,000 in unspent federal matching funds, as the law requires.

However, he said he will remain a member of the Republican Party and will not form a third party. As an independent, Anderson will not campaign in the remaining GOP primaries; he will attempt to defeat the Republican and Democratic nominees in the Nov. 4 general election.

His candidacy puts a new, largely unpredictable element into the 1980 presidential race, one that has made Republicans and Democrats alike uneasy.

Anderson told a crowded press conference at the National Press Club that he realized his candidacy was "fraught with many obstacles."

"But on balance, the obstacles pale when one considers that too many people in our nation are disillusioned with the prospective choices our party structures are offering," he added. "The result is frustration, apathy and despair."

Anderson's prepared speech was a reserved, almost defensive document laying out the rationale for his candidacy. It mentioned only one potential November opponent -- President Carter.

"The current administration has demonstrated a total inability to chart a clear, commonsense economic policy that is capable of arresting our domestic economic decline," he said at one point. Later, he added, "America will not tolerate a president who puts his finger to the prevailing political winds, rather than to the pulse of an anxious nation."

It was only under questioning that Anderson attacked Republican Ronald Reagan, stating: "I simply cannot accept the philosophical beliefs of a man who I think is largely wedded to the past."

As for the other two remaining presidential candidates, Republican George Bush and Democratic Sen. Edward M. Kennedy, he said the possibilities of their gaining their party nominations are "utterly beyond the scope of what's a reasonable expectation."

Anderson, 58, is a ruddy-faced, snowy haired 10-term congressman from the northern Illinois city of Rockford. A lawyer and son of a Swedish immigrant, he entered Congress as a conservative but gradually moved to a more moderate course on many social issues, accumulating a voting record that many in his district considered too liberal.

Until recent months, he was a staunch Republican and defender of the two-party system. For 10 years he serves as chairman of the House Republican Conference, the third-ranking position in the House GOP heirarchy. And when he was challenged by an arch-conservative in his 1978 primary, he called in a host of the party's biggest guns to hang on to his seat.

In a debate sponsored by the American Enterprise Institute after the 1976 election, Anderson criticized former Minnesota senator Eugent McCarthy for running an independent candidacy that year.

"When I see all of the trouble that the Italians and some of our other European friends have in forming a government, I am darned glad we have a two-party sytem in this country," a transcript quoted Anderson as saying. ". . . I am not going to sit here quietly and listen to you denigrate the two-party system. It has served our country well over the last 200 years."

Anderson yesterday came under the same kind of criticism he issued only four years ago against McCarthy. Republican National Chairman William Brock called his candidacy move a "regrettable one," and scheduled a news conference for today on the topic. Anderson's Maryland coordinator, Anne Lewis resigned from his campaign, saying she could no longer support him.

House Speaker Thomas P. (Tip) O'Neill Jr. predictted Anderson has no chance of victory. "I feel sorry for John, he is a nice fellow," he told reporters. "You put a fellow in the spotlight, give him a little television, and he gets an ego kick."

The liberal Americans for Democratic Action issued a statement charging anderson's voting record is not that of a liberal, except on civil rights. It noted Anderson supported the Vietnam war as late as 1973, is a longtime opponent of organized labor and is a supporter of nuclear power.

Anderson, who became a GOP candidate last June, has been one of the biggest surprises of the 1980 campaign. Until he scored suprising second place finishes in the Vermont and Massachusetts primaries, he was regarded as the darkest of the party's darkhorses.

Running as a evangelist of "new polititics," he hoped to capitalize on what he called "the Anderson difference" and win upsets in the Illinois and Wisconsin primaries. But he fell short in both and increasingly began talking about a race as an independent.

His announcement speech yesterday didn't mention either "new politics" or "the Anderson difference." Instead, he spent much of it defending his move.

"I strongly disagree with those who claim that my intended action to run an independent candidacy places me in the role of a so-called spoiler," he declared.

"I think in giving myself the option, and giving the American people the opportunity to vote for me in November, I am broadening the base of the political process in this country," he said. "This is not an assault on the two-party system."

Anderson is basing his candidacy on polls that show he has the support of about one-fifth of the American electorate. A recent Washington Post poll showed him with 17 percent. He is putting together an essentially media-based campaign which he thinks can be financed for $10 million to $12 million.

Half the public, he said, "still has little information about me . . . I can reach out and touch those people."

His candidacy has cuased the greatest concern among supporters of Carter, who fear he will draw voters away from the president in November.

"On the margin, Anderson hurts Carter more than he does us in some key battleground states -- New York, Pennsylvania, Ohio and especially Illinois," said Richard B. Wirthlin, Reagan's chief strategist and pollster.