Liberal Leader Justin Trudeau faced a barrage of attacks throughout the 40-day election campaign, but in the end, he did enough to earn back Canadians鈥 trust for another term as prime minister.

By the time the dust settled on the election, Trudeau lost the popular vote and more than 20 seats in the House of Commons, but was able to maintain a minority government and will remain prime minister.

鈥淚t has been the greatest honour of my life to serve you for these past four years and tonight you鈥檙e sending us back to work for you,鈥 Trudeau said during his victory speech early on Tuesday. 鈥淲e take this responsibility seriously and we will work hard for you, for your families and for your future.鈥

As of Tuesday morning, the Liberals were elected or leading in 157 ridings, compared to the Conservatives鈥 121, the Bloc Quebecois鈥 32 and the NDP鈥檚 24.

鈥淵ou are sending our Liberal team back to work, back to Ottawa with a clear mandate,鈥 Trudeau said. 鈥淲e will make life more affordable. We will continue to fight climate change. We will get guns off our streets and we will keep investing in Canadians.鈥

While the Liberals lost 20 seats compared to 2015, Trudeau鈥檚 strategy appeared to pay off.

While the Liberals lost 27 seats, Trudeau鈥檚 strategy of focusing on the three battleground provinces of Quebec, Ontario and British Columbia appeared to pay off.

Heading into the election, experts predicted the 905 region of the Greater Toronto Area, which surrounds Toronto, could prove pivotal as it had been a Liberal stronghold in 2015, but appeared to have a lot of seats up for grabs.

The Liberals ended up locking down the region by winning all but four of the seats, including a win for former Olympian Adam van Koeverden in the Milton riding over deputy Conservative Leader Lisa Raitt, who had held the seat for the past 11 years.

In Quebec, the Liberals nabbed 35 seats, a drop of five seats from 2015. The Liberals nabbed all but two seats in Montreal, home of Trudeau鈥檚 Papineau riding.

In British Columbia, the seats were more evenly distributed between the parties, but the Liberals were elected or leading in 11, including six in Vancouver and the surrounding area.

The Liberals completely swept the Atlantic provinces in 2015 and were expected to regress from there this time around, but they still held a significant lead in the region. In all, the Liberals won 25 of the 32 ridings in Atlantic Canada, including the home ridings of all five cabinet ministers from the area.

As expected, the Liberals did not produce many results in the Prairies, having been completely shut out in Alberta, and in Saskatchewan, where long-time MP Ralph Goodale lost the riding of Regina-Wascana he鈥檚 held since 1993.

The Liberals did manage to claim four seats in Manitoba, all of which are in Winnipeg.

In the North, Trudeau swept all three available seats, but lost Nunavut this time around.

The Liberals also failed to capture the popular vote, falling some more than 243,000 votes behind the Conservatives.

 鈥淭o those that did not vote for us, know that we work every single day for you,鈥 Trudeau said. 鈥淲e will govern for everyone. Regardless of how you cast your ballot, ours is a team that will fight for all Canadians.鈥

THE LIBERAL PLATFORM

The Liberals ran on a platform under the tagline 鈥渋nvesting in Canadians.鈥 Under the plan, the Liberals pledged to expand the Canada Child Benefit to 15 per cent for children under the age of one, offered relief for student debt, additional taxes on the wealthiest Canadians and new regulations for the world鈥檚 largest tech companies.

Under the Liberal plan, Canadians earning less than $147,000 annually would not pay income tax on the first $15,000 they earn, which the party says would lift 40,000 citizens out of poverty.

The Liberals have also pledged to help students dealing with debt with the option of extending the grace period for loan payments to two years and increasing student grants under the Canada Students Loans and Grants program by $1,200, to reach $4,200 per year.

When it comes to climate change, the Liberals promise to achieve net-zero emissions by 2050 and to keep the carbon tax.

THE CAMPAIGN

While Trudeau ran his re-election campaign under the slogan 鈥渃hoose forward,鈥 it was his past that dominated the discussion on the trail.

The Liberals鈥 tumultuous election campaign was  highlighted by the now-infamous photos of Trudeau wearing blackface and brownface in several instances.

The first photo emerged on Sept. 18 and showed Trudeauin brownface at an Arabian Nights-themed partyin 2001, during his time as a teacher at the Vancouver private school West Point Grey Academy.

Within hours, the photo made international headlines and by the next day, other photos and videos of Trudeau in blackface, from his younger years, also emerged.

For a leader who had spent the previous four years championing diversity and vowed to fight any forms of discrimination, the photos dealt a significant blow to his credibility among visible minority and Indigenous voters.

Trudeau was bombarded with questions about the photos over the next several days. The Liberal leader apologized profusely for the images. He said he did not think his actions were racist at the time, but had come to realize the opposite.

In the next weeks of the campaign, focus shifted to the debates, where Trudeau notably skipped out on the Maclean鈥檚/CityTv debate and the Munk Debates foreign-policy event, instead choosing to focus on the only two official debates and the TVA debate.

During the French-language debate, Trudeau took another hit when Conservative Leader Andrew Scheer called him a hypocrite for boasting about his environmental record while using two planes for his campaign.

The Liberals defended the two planes by noting that the party is purchasing carbon offsets for all campaign transportation on planes and buses,

Trudeau facedmore heat throughout the campaign over his ethics violation in the SNC-Lavalin scandal, the stalled Trans Mountain pipeline project, the carbon tax and a broken promise on electoral reform.

Still, Trudeau managed to get the most high-profile celebrity endorsements of any party leader, notably:  former U.S. President Barack Obama and Toronto Raptors President Masai Ujiri.

THE FIRST FOUR YEARS

Trudeau walked onto the world stage with a bang when he won a majority government in 2015, but enthusiasm dwindled over the past four years in part due to ethics scandals, racist costumes and a stalled pipeline project.

During his tenure as prime minister, Trudeau has tried to walk the fine line between fighting climate change while also pledging to build the Trans Mountain Pipeline expansion, and in turn left some voters on both sides feeling alienated.

Still, Trudeau鈥檚 government passed legislation to legalize marijuana during his time in office, made Canada a world leader when it comes to resettling refugees and negotiated a new NAFTA deal and a revised Trans-Pacific Partnership.