The federal Liberals have come up with a victory in Toronto Centre, the downtown riding they have held for two decades and which they fought to hang onto in a hotly contested byelection.

Liberal candidate Chrystia Freeland won the seat with 17,081 votes, handily defeating the NDP's Linda McQuaig with 12,643. 

"We did it!" Freeland said as she thanked her supporters late Monday evening, about two hours after the polls closed, as the results moved in her favour.

The byelection marks "the first act of the 2015 election," she added. 

Freeland and McQuaig had exchanged the lead several times as the early results came in, though the Liberal candidate eventually took and held the winning position. 

NDP candidate Linda McQuaig

Linda McQuaig wouldn't commit to running again in a general election, but she struck down the suggestion that the so-called 'orange crush' of NDP support is waning. (Amanda Margison/CBC)

McQuaig wouldn't commit to running again in a general election, but she struck down the suggestion that the so-called "orange crush" of NDP support is waning.

"We did better than we've ever done in Toronto Centre," she said. 

The final results from Elections Canada, at 2:05 a.m., also showed 3,024 votes for the third-place Geoff Pollock of the Conservatives and 1,024 for the Green Party’s John Deverell.

Seven other candidates in Toronto Centre received between 29 and 460 votes each. The byelection in Toronto Centre was triggered by the departure of Bob Rae, the former interim Liberal leader.

McQuaig is a well-known author and journalist. She has worked for the Toronto Star, the Globe and Mail, the National Post and Maclean’s magazine. Her website says that she has lived in the riding of Toronto Centre for 13 years.

Freeland is also a published author and journalist. Most recently, she had worked for Thomson-Reuters. Her website says she also resides in Toronto Centre, though she came under attack during the campaign for supposedly being a too-recent arrival to the riding. 

Freeland credited her win in part to having run a positive campaign. 

"I think people in Toronto Centre and Canada as a whole are tired of a negative, gladiatorial, buffoonish approach to politics," she said early Tuesday on CBC's Metro Morning. "They want politics that's about them and ideas about how to make life better."

The campaign in Toronto Centre saw NDP Leader Tom Mulcair and Liberal Leader Justin Trudeau each make repeated appearances in the riding. Both leaders were in Toronto as recently as the weekend.

Trudeau's support was "hugely important" said Freeland. "Justin is a fabulous leader of the Liberal party. He's a fabulous campaigner." 

Diverse, downtown riding

Toronto Centre is a diverse and densely populated riding. It is roughly bordered by Yonge Street, the Don River, Moore Avenue and Lake Ontario.

According to the Elections Canada website, there are more than 90,000 electors living in Toronto Centre.

Bob Rae speaks to reporters in Toronto Centre

The byelection in Toronto Centre was triggered by Bob Rae's departure from the House of Commons earlier this year. (CBC)

The riding was originally known as Rosedale, but became Toronto Centre-Rosedale after a redistribution in 1996. A subsequent redistribution in 2004 saw the name changed to Toronto Centre. Both times, the riding retained much of its original lands.

Toronto Centre had been a Liberal-held riding since 1993.

Before Rae became the MP in 2008, the riding was held by Bill Graham from 1993 onward.

Rae spoke briefly with reporters in Toronto Centre on Monday, where he was casting his own ballot.

Asked about the Liberals’ success in the riding over the past two decades, Rae said that parties can’t get complacent about elections.

"You don’t take anything for granted," Rae said. "Each election is a new ballgame, each election is a new set of choices, new names on the ballot, new candidates knocking on your door and meeting you."

The federal byelection in Toronto Centre was just one of four taking place across three provinces on Monday.

The Liberals and candidate Emmanuel Dubourg also won in Montreal's Bourassa riding. 

Larry Maguire won Brandon-Souris for the Conservatives, as did Tory Ted Falk in Provencher. Both ridings are in Manitoba. 

With files from CBC's Genevieve Tomney