QUINCY — State Democrats elected longtime activist Gus Bickford as the party's new chairman Monday night in a tight election that took place as Democrats began to look ahead to the 2018 election and learn from President-elect Donald Trump's shocking victory last week.

Bickford, of Westford, beat out the party's 2014 nominee for lieutenant governor, Stephen Kerrigan, on a second ballot after the third contender for the job, Suffolk County Sheriff Steven Tompkins, urged his supporters to back Bickford after one round of voting.

"We begin now for 2018," Bickford told the more than 300 Democrats assembled at Quincy High School after his victory.

Despite Gov. Charlie Baker's popularity, state Democrats are feeling newly resurgent after the elections in which Baker, a Republican, threw much of his political capital behind a ballot question to expand charter schools. The question lost by a significant margin, and Bickford, who worked on the "No on 2" campaign as a consultant, said the party can learn from that win and the way opponents communicated their message to voters at the local level and through social media.

"That campaign plan is our blueprint for 2018," Bickford said.

The three men who sought to succeed outgoing party Chairman Sen. Thomas McGee have been aggressively courting Democratic Party members for the past two months in the midst of an election cycle that ended with the party forced to engage in deep self-reflection following the election of Trump as president.

Kerrigan had the advantage entering the night, and on the first round of balloting finished first with 138 votes, 15 shy of the 153 votes needed to win the required majority. Bickford finished second after the first round with 105 votes and Tompkins had 62 votes.

Before the second round of balloting, Tompkins dropped out of the running and, in a surprise to Kerrigan's team, urged his supporters to back Bickford, who surged to 156 votes on the second ballot to Kerrigan's 148. Bickford told the News Service that no promises were made Tompkins in exchange for his support.

Tompkins' status as an elected official seemed to work against the sheriff. After three years under Sen. Thomas McGee's leadership, many party members said they were looking for a full-time chairman to lead them into the next election cycle.

"I just think it would be good to have a chair that's not an elected official, but full-time," said Candy Glazer of Longmeadow who chaired Sen. Eric Lesser's successful re-election campaign and was supporting Kerrigan entering the night.

Patrick McDermott, a state committee member from Quincy who is also Norfolk County Register of Probate, expressed a similar sentiment. "I was never a fan of having a member of the Legislature take on the job of party chair because your loyalties are sometimes in two or three places," he said.

McDermott backed Kerrigan on the first ballot for both his connections to party activists and ties to Washington that could help him raise money for the party. "I think Steve's background is stellar and he ran a true grassroots campaign for lieutenant governor," he said. He continued, "The last time we had true success was with John Walsh."

Walsh, the architect of Deval Patrick's first successful campaign for governor who chaired the party during the Patrick era, has widely been credited with building the Democratic Party's modern grassroots infrastructure. He backed Bickford in Monday's contest, deciding only on Sunday who he would support.

"I backed Gus because of experience. He's got experience in all areas of the party," Walsh said, adding that he could have easily supported Kerrigan or Tompkins as well and believes both will remain leaders in the party.

Bickford, who runs the consultancy and data analytics firm Factotum, is a long-time party insider and member of the Democratic National Committee from Massachusetts who previously worked as executive director of the party in the early-to-mid 1990s under then chairwoman and Sen. Joan Menard. After his victory, Bickford resigned his national committee post and the party will have an election for a new committeeman at its next meeting.

Bickford touted his role in pushing former Democratic National Committee Chairman Howard Dean to develop a national voter file and said he helped write the national party's "50 state strategy." He has also worked on the campaigns of U.S. Rep. Niki Tsongas, Sen. Elizabeth Warren and Hillary Clinton.

Bickford said his focus will be to start now to train grassroots activists and local town and ward chairs to deliver the Democratic message to voters in their communities, whether through social media or on the soccer fields.

"We learned in this last cycle that people are getting their message in a different way. We need to be able to take our message and deliver it locally. Question two gave us a blueprint for how that would work," Bickford said.

Former Treasurer Steve Grossman, who once ran the Democratic National Committee and who backed Kerrigan, said Bickford will require no on-the-job training.

"I think Gus will do fine. I think Gus is an organizer, Gus is one of those people who understands that coming out of this election the revitalization of the city ward and town committees, bringing new blood and younger activists. People want you to lay out who you are and what leadership are you going to provide and how are you going to affect the quality of my life, and Gus understands that."

Kerrigan, who worked for the late Sen. Edward Kennedy and ran President Barack Obama's 2012 national convention in Charlotte, North Carolina, came into the state committee election with the backing of many elected leaders, including Senate President Stanley Rosenberg and Attorney General Maura Healey.

Kerrigan, who is openly gay, said Democrats need to fight for values of a party that made it possible for him to marry his partner, and Tompkins, who is African American, said the party needs to bring more people of color, women and those in the LGBT community into its organizational fold.

"We've got to re-enengage folks. If we learned nothing from last week we have to learn this. There are massive numbers of voters we aren't talking to," said Kerrigan, who spoke in his pitch to party members about the need to train local captains in every community.

Sen. Harriette Chandler, of Worcester, also put her support behind Kerrigan. "I've known him. I've seen him in action. And he's from central Mass. And has the organizational skills we need to reorganize the party," she said.

Many Democrats, however, were torn between the choices. Former House Speaker Charlie Flaherty told the News Service he was undecided walking into the meeting. "I haven't made up my mind. Three good choices," he said.

Other elected officials didn't want to pick sides, perhaps knowing they would have to work with whomever prevailed. House Speaker Robert DeLeo stayed out of the contest and did not attend Monday's election, while Auditor Suzanne Bump abstained. "I'm not going to be participating," she told the News Service before the vote. "We have several worthy candidates and I think it's important for the grassroots to speak."

Glazer said the February caucuses will be an important time for the party to keep Democrats frustrated by last Tuesday's national election engaged in the process. She said she believes Baker is "vulnerable."

"I feel better going against the governor after the election," she said, referring to Baker's unsuccessful efforts in western Massachusetts on behalf of Sen. Lesser's opponent and for the ballot question to expand charter schools.

Statewide, Republicans picked up one seat in the House and defended all 40 GOP lawmakers seeking re-election in an anomaly for the party that has grown accustomed to losing ground on Beacon Hill in presidential election years.

Paul Craney, executive director of the conservative Massachusetts Fiscal Alliance, offered Bickford his advice for moving forward after the election.

"A Democratic Party that embraces the agenda of ordinary working families is a party with a future. A MassDems party that continues on its road to left wing radical progressivism will shrivel under its own elitist spine," Craney said.

Walsh agreed that Baker could be vulnerable, noting that Martha Coakley and Kerrigan lost to Baker and Lt. Gov. Karyn Polito in 2014 by just 18 votes per precinct in the second-lowest gubernatorial election turnout year in the past 50 years.

Though Baker distanced himself in this most recent election from Trump, Walsh accused the governor of "running a pretty nasty anti-Democratic agenda," including his efforts to privatize some activities at the MBTA.

"I don't think you need to pretend that Charlie Baker is Donald Trump to articulate a case against him," Walsh said.

The party is expected to take up a resolution at its next meeting to "oppose further attempts by Governor Baker and MBTA leadership to privatize services and functions of the MBTA."