Edward Andrews, the veteran Montgomery County school administrator who has spent weeks saying no to the top job in the country school system, finally agreed last night to accept appointment as superintendent.

The decision by Andrews, who has worked for the county schools for 23 years and has been acting superintendent since June, ends an eight-month search that has cost the county nearly $20,000. He will succeed Superintendent Charles M. Bernardo, whose departure was forced by the school board last spring.

Andrews' four-year appointment was announced by board chairman Daryl Shaw last night after an hour-and-a-half closed meeting at which only one of the board's seven members dissented. Andrews, Shaw said, "has impressed the board, staff and community with his leadership ability. He has improved staff morale, given leadership . . . and taken the initiative on a number of tough jobs. . . ."

Andrews, unsmiling, listened to the applause of about 100 staff members, then pledged to "do the best I can."

Since October, while the board conducted an intensive search for a new superintendent, considering about 80 candidates from outside the system, Andrews insisted he was not a candidate.

He maintained he did not want to lose his personal life to the long hours of board meetings and administrative sessions that a superintendent must attend. Teachers, staff and community leaders continued to ask him to reconsider.

As the pressure increased, Andrews said he would take the job only if the board was unable to find anyone else.

As recently as yesterday morning, Andrews refused renewed pleas from board members.

Yesterday afternoon, according to board president Shaw, Jack L. Davidson, the only one of the 80 outside candidates brought to Montgomery for interviews, withdrew from consideration in a phone call.

Davidson, who has headed the schools in Austin, Tex., said he regretted not knowing of Andrews' interest in the job before his visit to Montgomery last week, Shaw said. "I can understand the desire of many persons to avoid more changes than necessary," Shaw quoted Davidson as saying.

The vote to hire Andrews was 6 to 0, with the seventh baord member, Joseph Barse, abstaining, Barse said he then changed his vote to no.

Barse later told a reporter the selection process "was extremely biased from the beginning. Ed Andrews has been the one and only candidate [Wanted by some members] since before the search started . . . At no time has there been a formal comparison of Ed Andrews with the other candidates or an in-depth interview on topics we discussed with the other candidates."

The superintendent's job was advertised at an annual salary of $60,000.

Andrews, 44, who joined the Montgomery system in 1957, teaching English, geography and social studies at Sherwood High School in Olney, is a congenial figure who greets janitors and administrators alike by name and with a friendly grin.

David Eberly, president of the teachers' union, called him "one of the most competent and humane administrators in the school system."

One of the first challenges Andrews will face as superintendent will be negotiating a new contract with the county's 6,000 teachers represented by Eberly's organization, the Montgomery County Education Association.

The departure of Bernardo, Andrews' predecessor, from the school system followed the election of a new, conservative school board majority that had pledged to seek his ouster.

The majority claimed that Bernardo alienated many parents by choosing to close 21 schools with declining enrollments and that he lowered teacher morale by implementing several innovative but untested programs, including a mandatory black studies course for faculty.