Citing the success of campaigning directly to the voters, Democratic challenger Daniel T. Drew unseated Middletown’s Republican Mayor Sebastian N. Guiliano by 645 votes Tuesday.

The final tally was 4,868 votes for Drew and 4,223 for Guiliano. Independent candidate Christine Bourne picked up 172 votes. This was Drew’s second bid for the mayor’s office; he narrowly lost to Guiliano in 2009.

“I’m very, very humbled by the confidence and trust the people of Middletown put in me and I will work hard every day to fulfill that trust,” said Drew, who was a member of the Common Council. The campaign’s success, he said, came from “a lot of hard work and shoe leather” and listening to people one-on-one. “It’s the hardest way to run a campaign but the best way,” Drew added.

His priorities when he takes office next week, Drew said, include seeking ways to reduce taxes, spurring economic development and improving city hall’s relationship with the school system.

Dropping in to congratulate Drew during his victory celebration at the New England Emporium on Middletown’s Main Street was Gov. Dannel P. Malloy and Lt. Gov. Nancy Wyman. Malloy said he took an interest in Drew’s candidacy because of his potential.

“I got to know Dan Drew when he ran as a newcomer two years ago and I appreciate that he stuck around,” said Malloy, adding that he knows what it’s like to come back after losing an election. “I like him and I think it’s incumbent upon those of us in office to help and mentor talent and he’s a talent.”

The attention paid to Middletown’s mayoral race by Democrats statewide was an issue during the campaign and cited by Guiliano as a factor in his defeat.

“Relax, everyone, we lost an election, we didn’t lose our lives,” Guiliano said to a room full of supporters at Republican headquarters. “And it took the entire Democratic machine in the state of Connecticut to do it. That’s what we went up against.”

He added they all owed the new city leaders their support “when they do the right thing.”

Earlier in the day, Chris Healy, the former Republican State Chairman who was Guiliano’s campaign manager, said one of the challenges he faced was trying to overcome the amount of time and money Democrats were focusing on the Middletown race. “On a statewide perspective, the Democrats put a lot of resources into the Drew campaign and heavily solicited money from state lobbyists,” Healy said.

But Drew’s campaign manager, state Rep. Geoff Luxenberg of Manchester, said that Drew received more “grassroot” contributions than both of his opponents combined, adding that some of Guliano’s contributions came from city contractors.

Documents submitted by Drew’s campaign team showed that he received $44,042 from individuals and $7,600 from other committees. Among the contributors to Drew’s campaign were the State Employee International Union local 32BJ and Central Connecticut Carpenters of local 24. Guiliano received $49,670 from individuals and $2,000 from other committees. Bourne received $3,000 from individuals.

Drew defeated Bourne in a primary for the mayor’s candidacy. Bourne decided to challenge Drew for the mayor after Democrats failed to endorse her for city treasurer, a post she held for 16 years.

The primary challenge may have helped Drew in the long run, Malloy noted Tuesday. “I think it made him a better candidate.”