Montgomery County dentist Allan Levey was elected chairman of the state's Republican Central Committee yesterday in what officials said was a victory for the party's moderate faction.

Levey, who was formerly the finance chairman for the party, beat Donald J. Devine, who ran last year for state comptroller on J. Glenn Beall's ticket, in yesterday's close. hotly contested race for party chairman.

Devine, who ran Ronald Reagan's 1976 presidential campaign in Maryland, was supported by Rep. Robert Bauman. Some Republicans saw yesterday's election as a test of Bauman's strength within the party should he choose to challenge Republican Sen. Charles McC. Mathias in the next Republican senatorial primary.

Levey, who was the chief fund raiser in the campaign for Prince George's County Executive Lawrence J. Hogan, had the support of many Mathias backers, according to State Sen. Howard Denis of Montgomery County.

Levey said that under his direction, the party will concentrate in the next four to eight years on increasing its voter registration, building up a precinct level organization, and getting more Republicans elected to county and statewide office.

There are only seven out of 47 Republicans in the State Senate and 16 out of 141 in the House of Delegates. Republican county executives have been elected only in Anne Arundel County and Prince George's County.

"I think the Republican Party has a great future in Maryland. What we're lacking is a grass roots organization in the state," Levey said.

Levey received most of his support from Prince George's and Baltimore Republicans, Denis said.

Denis said Montgomery committee members were split 10 to 8 in favor of Levey, who resides in Potomac and has his dental practice in Oxon Hill.

Devine, who lives in Kensington, had been the central committee's parliamentarian for the past few years. He is a professor of government at the University of Maryland in College Park.

Devine said in an interview after the election that he may now consider challenging Mathias, a party moderate, in 1980.

Mathias denied there was a connection between yesterday's election and the possibility of a future battle between himself and Bauman.

Bauman, Mathias said, "has said publicly a number of times he wouldn't oppose me." Bauman could not be reached for comment last night.

Devine had been considered the slight favorite in the race, but virtually at the last minute, the contingent from Washington County switched their seven votes to Levey.

Levey said he felt he was viewed by most committee members as "the candidate who could bring the party together," while Devine was associated more with the party's conservative wing.

Devine said he felt he was hurt by the fact that several party members from the Eastern Shore, which is one of the more conservative areas in the state, were unable to attend yesterdays' convention, which was held in the Ramada Inn in Lanham.

Levey was elected to replace State Sen. Aris T. Allen of Anne Arundel County, Allen, a party moderate, ran for lieutenant governor on the Beall ticket last fall. He was recently appointed to the State Senate to fill the seat of the late Sen. Edward Hall of Calvert County.

Among the other committee officers elected yesterday were: Joan Athan of Howard County, first vice chairman; Patrick Carter of Baltimore County, second vice chairman; Stan Eckles of Montgomery County, third vice chairman; Jeannette Wessel of Baltimore treasurer; Arlene Baybutt of Talbot County, secretary.

Levey said he has asked Devine, who resigned as parliamentarian, to continue working in the Republican Party.