OTTAWA — It started as a lark: A party needed somebody, anybody, on the ballot for an unwinnable seat in Quebec, and some friends nominated Ruth Ellen Brosseau, an unknown single mother in her 20s who worked in bars and did not even live anywhere near the district.

Then it was a fluke: She won the seat in 2011 without ever campaigning for it, riding a tide of voter dissatisfaction with the status quo and the last-minute popular appeal of the party’s leader at the time, Jack Layton.

Now her story has become an underdog’s triumph worthy of a Frank Capra movie: In one of the bigger upsets of the Canadian elections last week, Ms. Brosseau handily won re-election to Parliament, even as her party, the left-leaning New Democrats, took a beating across the country.

The voters had many surprises up their sleeves last week. Instead of the close national race with no clear winner that was forecast by opinion polls, they delivered a sweeping victory and governing majority to Justin Trudeau and his Liberal Party and ejected incumbents on both the right and the left.