Conservative firebrand Jim Lyons will take the reins of the state Republican Party, a changing of the guard from the moderate establishment led by Gov. Charlie Baker that had controlled the organization.

Lyons, a four-term Andover Republican state representative who lost his bid for re-election last year, beat party treasurer Brent Andersen, 47-30, in a vote by the party’s state committee Thursday night, according to the party.

The colorful Lyons is known for having derailed a transgender-focused bill that would have added a third gender to Massachusetts driver’s licenses — by insisting that 73 “genders” be recognized instead of just the “X” the sponsors were seeking. He also forced the state to admit that it annually doled out $1.8 billion in welfare payments to illegal immigrants. He was well known around the State House for hosting a nativity scene, which drew protests from atheist groups.

Lyons said in a statement after the vote, “I am humbled by the trust placed in me by my fellow members of the Massachusetts Republican State Committee, and look forward to working with them in the years ahead to grow and unify our Party and secure victory in 2020. I want to thank Brent Andersen for running a strong race and offering compelling ideas for our Party’s future, and I commit to working with him to engage our grassroots, strengthen our resources, and connect with a broad coalition of voters to advance our common vision.”

Andersen was seen as the establishment choice, a moderate New England Republican in the vein of Baker, and former governors Mitt Romney and William Weld, and other statewide elected Republicans in deep-blue Massachusetts.

Lyons will replace Kirsten Hughes, who has held the chairmanship for six year. The Quincy city councilor — and Baker ally — decided against a run for re-election for the chair in November as a contest for the future direction of the state party began to heat up.

During last year’s campaign season, Baker took some flak from the left for campaigning with Lyons, due to Lyons’ more conservative views, particularly on LGBT and abortion issues. The two were seen as representing divergent branches of the GOP.

Lyons entered the GOP chairman race after former state Rep. Geoff Diehl, who lost a bid to unseat U.S. Sen. Elizabeth Warren last year, decided against running for the position, even though he was considered the favorite. Diehl ultimately endorsed Andersen, as did Beth Lindstrom and John Kingston, the other two GOP U.S. Senate hopefuls from last year.