TORONTO — Prime Minister Justin Trudeau has survived scandal and missteps to win a plurality of seats in Parliament in Canada’s federal election, news media here projected, but he failed to retain his majority, leaving his government dependent on the support of smaller parties to advance his agenda.

Trudeau’s Liberal Party has won more seats than Andrew Scheer’s Conservatives, the Canadian Broadcasting Corp. and CTV News projected shortly after polls closed Monday night, but fell short of the 170 needed for a majority in the 338-seat House of Commons. As of late Monday night, preliminary results from Elections Canada indicated that the Liberals were leading or had won 155 seats — down from the 184 they won in 2015. The Conservative Party was in second with 122 seats, but led in the popular vote.

“From coast to coast to coast, tonight, Canadians rejected division and negativity,” a hoarse-voiced Trudeau told a roaring crowd of supporters in Montreal after 1 a.m. Eastern time Tuesday. “They rejected cuts and austerity and they voted in favor of a progressive agenda and strong action on climate change.”

Despite losing his majority and the popular vote, he said the results meant he had a “clear mandate.”

Speaking to supporters in Regina, Saskatchewan, Scheer said he was “disappointed,” but that Conservatives had “put Trudeau on notice.” When Trudeau’s government falls, he said, “Conservatives will be ready and we will win.”

The election will create Canada’s fourth minority government in 15 years, and delivers a setback for Trudeau, the 47-year-old Liberal leader who swept to power in 2015 with a stunning landslide victory.

Without a majority, Trudeau could try to pass bills on a case-by-case basis, negotiating for the support of one or more of the other parties. He could also establish a formal coalition, in which parties share cabinet seats, but such arrangements are rare in Canada. Both the third-place separatist Bloc Quebecois and the fourth-place New Democratic Party appeared to have enough seats to help the Liberals stay in power.

The first test of a minority government is the Speech from the Throne, in which the leader puts forth his agenda, and it’s put to a vote. If Trudeau loses, his government collapses. The governor general, who represents the queen in Canada, could then call on other parties to try to form a government to avoid another election.

The vote Monday capped an acrimonious contest dominated by scandal and personal attacks. Polls throughout the six-week campaign showed Trudeau’s Liberals in a dead heat with Scheer’s Conservatives, a competition that would have seemed far-fetched when Trudeau came to power four years ago, riding a wave of support reminiscent of the enthusiasm for his father, longtime Prime Minister Pierre Elliott Trudeau, a generation earlier.

But unkept promises and scandal blunted the telegenic Liberal leader’s prospects. He cast himself as a steward of the environment but bought an oil pipeline last year for $3.4 billion. Jody Wilson-Raybould, his former attorney general and the first indigenous woman in that role, accused him and his senior aides this year of improperly pressuring her to interfere in the criminal prosecution of SNC-Lavalin, a Quebec-based construction giant. Last month, images and a video of a younger Trudeau in brownface and blackface damaged his reputation as a champion of diversity. He apologized, repeatedly.

“He can’t even remember how many times he put blackface on, because the fact of the matter is he’s always wearing a mask,” Scheer, 40, crowed during one debate.

But Canadians did not appear to warm to Scheer, a “pro-Brexit before it was cool” father of five, who struggled to expand support for the Conservatives outside their base and failed to capitalize on Trudeau’s missteps. He drew criticism for his opposition to abortion, his refusal to say whether he still opposed same-sex marriage, and for the revelation late in the race that he held U.S. citizenship — after he and his party had criticized other lawmakers for their dual citizenship.

In Quebec, a province known for large swings from one election to the next, the resurgence of the once moribund Bloc Quebecois after years of internal strife was one of the surprises of the campaign. Yves-Francois Blanchet, the former rock group manager who leads the party, told supporters in Montreal that he believed that Canadians wanted all of the parties to work together “despite the deep divisions” of the electoral map.

Jagmeet Singh’s New Democratic Party trailed the Bloc Quebecois with 25 seats, but was still in a position to hold the balance of power in a minority government.

Before the election, the Green Party appeared poised for a breakthrough given concern about climate change in Canada and dissatisfaction with the Liberal government’s record on the environment. But Elizabeth May’s party won only one new seat, bringing the party’s total seats in Parliament to three.

There were a few other notable results.

Wilson-Raybould, who was booted from caucus after the SNC-Lavalin affair, ran as an independent in British Columbia — and won. Maxime Bernier, the former Conservative lawmaker who quit the party last year to form the hard-right People’s Party of Canada in 2018, lost his seat.

In Mississauga, Ontario, an ethnically diverse, middle-class Toronto suburb, about two dozen voters lined up outside a gymnasium at St. Jude Separate School early Monday waiting for the polls to open. A kindergarten teacher explained to her wide-eyed students: “They’re picking our prime minister.”

But for Moez Mawani, the campaign was uninspiring. The retired business owner voted for the incumbent Liberal candidate in his district, but with no great enthusiasm.

“It was a matter of picking the better of the two evils,” he said.

Terence Norton, a retired director of a pharmaceutical company, opted for the Conservative challenger. He said the Conservatives would “put more money in the pockets of average Canadians.”

Nawal Khokhar said she voted with the future of her young daughter in mind. The 28-year-old business consultant cast a ballot for Navdeep Bains, the local Liberal candidate, who was innovation minister in Trudeau’s cabinet. She said she was not wooed by the Conservatives’ promise of tax cuts.

“Am I okay with getting a little bit better of a tax cut today but having my child grow up in an environment that isn’t as inclusive?” she asked. “That’s really my choice.”

Simon Malevich, a graduate student at the University of Toronto, was one of the 4.7 million people who voted early. He cast a ballot for the Conservatives in 2015, but has since had a “change of heart” — this time, he voted for the New Democratic Party.

“I don’t think Justin Trudeau has lived up to the promises that he made in 2015,” said Malevich, 24. “I’m worried about inaction on climate change. I don’t think it was a good idea that we bought a pipeline.”

He said the campaign left much to be desired.

“This election hasn’t been about policy ideas between the two major parties,” Malevich said. “It has been about ‘gotcha’ moments.”

Canada’s federal elections watchdog said last week that 29 percent more people voted early than in 2015. It was the first federal election since the Supreme Court ruled in January that expats have the right to vote no matter how long they have lived outside Canada. Previously, Canadians who had lived abroad for more than five years were ineligible.

Canadians complained that the campaign was heavy on name-calling and light on issues. Trudeau wore a bulletproof vest at a rally in Mississauga this month after a security threat. He accused his Conservative foes of running the “nastiest” campaign in the country’s history.

At a packed rally in Richmond Hill, Ontario, over the weekend, Scheer supporters aimed a chant of “lock him up” at Trudeau. Scheer tried to turn the chant to “vote him out.”

Canada’s foreign signals intelligence agency said this year that “some form” of foreign cyber interference in the election was “very likely.” The government established a panel of nonpartisan senior bureaucrats to monitor attempts at interference and to notify the public about serious incidents. It made no such announcements.

In a tweet early Tuesday, President Trump congratulated Trudeau for “a wonderful and hard-fought victory.”

“Canada is well served. I look forward to working with you toward the betterment of both of our countries!” Trump wrote.

The governor general is the representative of the monarch of Canada — currently Elizabeth II — in that country. An earlier version of this article described the governor general as the representative of the queen of England — not one of Elizabeth’s formal titles, and not the role in which she serves as monarch of Canada.