Montgomery County School Superintendent Charles M. Bernardo, whose ouster has been sought for months by the new conservative majority of the county Board of Education, has reached an agreement with the board that will result in his resignation in two weeks.

The agreement, announced by the school board last night following weeks of negotiations with Bernardo's attorney, will give Bernardo his salary through Dec. 12 plus an annuity of undisclosed size comparable to a pension.

The 41-year-old school administrator, who declared as recently as Tuesday that would stay on the $53,000 a year job despite efforts to remove him, said he feels "very, very secure in my future and optimistic about the future."

He said he has received several job offers "in both the public and private sectors," including one in the Washington area in which he is most interested. He did not elaborate on the offers he has received.

Bernardo will be succeeded by J. Edward Andrews Jr., a longtime county school administrator, who first will become acting deputy superintendent and then, on Oct. 1 interim superintendent while the board searches for a permanent replacement.

Andrews, 43, who has worked in the county school system since 1957, wrote his doctoral dissertation on negotiations and has been described by various of his associates as a "wound healer," "good, solid, pragmatic administrator" and "favorite son of the school system."

Andrews read a statement in which he said he will concentrate on "building public and staff confidence . . . reestablishing a climate of trust and co-operation with the black community . . . creating a workable means to continue the process of closing schools" and employe negotiations.

The agreement between Bernardo and the board is to be signed in two weeks. Thereafter, Bernardo is to take leave until his contract expires.

In return for pay through Dec. 12 - the first anniversary of the date the board notified Bernado of its intention to remove him - and the annuity, Bernardo agreed to resign and dimsiss his appeal of a court decision that would have forced him from office Oct. 1.

The conflict between Bernardo and the present school board majority had its origin before the election last November of the new conservative members, who had pledged to remove the superintendent from office and eliminate many of the changes he had overseen.

Bernardo was hired in 1975 from the Providence (R.I.) school system to reorganize and streamline the montgomery system in the face of declining enrollment.

Acting with the approval of the school board then in office, Bernardo instituted a major reorganization to abolish some top and middle-level administrative jobs, alienating some administrators; recommended closing 23 schools, irritating many neighborhood groups, and introduced a mandatory course in black culture for all school employes that some teachers thought unnecessary.

Bernardo also oversaw expansion of a computer-assisted math program and special education, disturbing some parents who wanted emphasis on traditional classroom-based instruction in "basics."

Bernardo became the focus of the frustration and anger felt by many of those opposed to the changes, and they expressed irritation also with his self-confident, assertive style and personal formality.

Last summer the old school board tried to prevent Bernardo from becoming an issue in the election - then five months away - by renewing his contract, due to expire at the end of September 1979, for four more years.

It didn't work. The conservatives made the school superintendent a major issue, and when they assumed office in December they filed suit seeking to revoke Bernardo's new contract.

In late March, a Circuit Court judge ruled in favor of the new board majority, invalidating the new contract given Bernardo by the old board. That cleared the way for the selection of a replacement Oct. 1 at the expiration of Bernardo's original contract.

Calling the ruling "scandalous," Bernardo appealed it.

"I brought aggressive and skillful leadership to the school system," he said at the time, "but it seems that only mediocre leadership has a chance to survive here very long."

By the time the judge had ruled on the suit, the board's majority members had begun to make the changes they had pledged.

The black culture course was made voluntary despite protests from black county residents led by the local NAACP.More than $4 million slated for administrative purposes was trimmed from the school budget.

Almost every vote was 4 to 3, and board debates were frequently marked by acrimony.

In early April Bernardo's attorney, Joseph D'Erasmo, began tentative negotiations with school board attorney Roger Titus, Bernardo acknowledged at the end of the month he had applied for the superintendency of the Broward County, Fla., school system and said he was considering other opportunities, but added, "My first choice is still the job I currently hold."

Bernardo said previously the school board's push to oust him resulted from an "island perspective" and that Montgomery County, with one of the largest and most affluent school systems in the nation, "is not as sophisticated as people believe" when it comes to making necessary compromises. "Here few people want countywide policies," he said. "They care only for their particular island."

Board President Martian Greenblatt has sought Bernardo's ouster since the time she was the only conservative on the old board.

For the last six months, with backing from the other members of the new majority, Joseph Barse, Eleanor Zappone and Carol Wallace, Greenblatt has won one battle after another. When the judge invalidated Bernardo's contract, Greenblatt said she was "ecstatic" and announced the search for a temporary superintendent."We need someone we can feel confident with, someone who will implement the policies of this board," she said.

Greenblatt last night praised "the close working relationship that now exists" between Bernardo and Andrews and said it "will ensure a smooth leadership transition."

Bernardo refused to talk about what led him to reach agreement with the school board. Asked by a reporter whether he felt a sense of relief, Bernardo said, "I never felt a sense of burden."