In a 5-2 decision, the Supreme Court said the regulation infringed on Canadian expats' constitutional right to vote, which Chief Justice Richard Wagner called a "fundamental political right" and "a core tenet of our democracy."
Prime Minister Justin Trudeau's Liberal government had already reformed the elections act, doing away with the five-year provision last month.
But the ruling was still widely viewed as important in that it would prevent future governments from bringing back the restrictions.
The impugned sections of the act had been on the books since 1993 but had only been used during the previous Tory government's decade in office, to 2015.
The law was challenged by two Canadians living in the United States. They both tried to vote in the 2011 election but were rebuffed due to the residency requirement.
Over the past century, Canada has expanded the right to vote, originally restricted to property-owning men aged 21 or older, to women, racial minorities, persons once described as suffering from a "mental disease," prison inmates and soldiers and diplomatic staff posted abroad.
Residence, the court noted, was one of the last restrictions on the right to vote in Canadian federal elections.
The majority of the court said the government failed to justify the measure, and called it overly broad.
"While it seeks to bar people from voting who lack a sufficient connection to Canada, no correlation has been shown between, on the one hand, how long a Canadian citizen has lived abroad and, on the other hand, the extent of his or her subjective commitment to Canada," said the ruling.
"Many non-resident citizens maintain deep and abiding connections to Canada through family, online media and visits home, and by contributing taxes and collecting social benefits," the justices noted.
In a dissenting opinion, Justices Suzanne Cote and Russell Brown called the five-year rule "a reasonable limit" on voting rights.
"Opening the vote to long-term non-residents... would be a regressive development, undermining the longstanding and entirely salutary practice in Westminster parliamentary democracies of privileging local connections in deciding who may elect local representatives," they wrote.
According to the government, an estimated three million Canadians or nine percent of the population live abroad.
Expatriate voting has historically been low.