In the final hours before a historic vote anticipated as a shift toward conservatism, Canadians pondered the shape of their country, and many decided abruptly, as they cast their votes, to stick with the current social agenda, political analysts said.

Although angry with the governing Liberal Party for financial scandals and ready for a change, in the end these Canadians voted for the devil they knew over the devil they did not know. Political analysts said the unexpected, though qualified, victory on Monday by the Liberal Party of Prime Minister Paul Martin was a result of fears that the Conservative Party had a hidden agenda. The analysts said the Liberals played up the Conservative agenda -- and voters listened. Some voters, the analysts said, feared the Conservatives, led by Stephen Harper, would cut taxes, repeal same-sex marriage rights, abandon environmental treaties, change immigration policies and move the country closer to the United States.

"I've heard people say anecdotally, 'My mother went into a booth to vote Conservative and came out Liberal,'" said John Wright, senior vice president at the Ipsos-Reid polling firm. Wright said the election never rested in the hands of undecided voters, but with swing voters in the vote-rich province of Ontario who switched at the last minute.

"The election was swung by 6 or 7 percent of the public who got up from the dinner table or lunch table and switched their votes," Wright said. "They got to the cliff and instead of turning right, they turned left."

Major public opinion polls in the last week of the campaign predicted a tight race, some even saying the Conservatives could become a minority government and end 11 years of Liberal rule. Harper, 45, the photogenic economist who had succeeded in uniting the conservative parties, had gained momentum. Amid the predictions, Harper was preparing to take over as prime minister.

"To put it in U.S. terms, a 'blue state' country nearly flipped and became a 'red state' country," said John Duffy, a Liberal Party strategist, referring to the U.S. practice of identifying Democratic states as blue and Republican states as red on political maps. "This Conservative Party is an unusual one in Canadian historical terms and is much less 'small l' liberal than any national party that has ever run before and come close to winning. It was a huge change that didn't happen."

When the votes were counted, the Liberals squeaked by with a minority government, winning 135 seats in Parliament, which now has 308 seats. The Conservatives, who were predicted to win more than 125 seats, won just 99, barely breaking out of their traditional strongholds in the West. The New Democratic Party won 19 seats, and the Bloc Quebecois won 54. "If you accuse someone of having a secret agenda, there is no adequate response," said Roger Gibbins, president of the Canada West Foundation, a public policy research organization in Calgary. "I think Harper had a tough time with that accusation. If I claim you have a hidden agenda and if you deny it, my response is of course you deny it because it is a hidden agenda. A hidden agenda can't be disproved."

Gibbins said another big issue in the campaign was a desire by many Canadians to stay as far as possible from policies similar to those of the United States. "George Bush played a far more important role in sharpening that debate about Canada-U.S. relations than Stephen Harper played," Gibbins said. "We haven't had an American president in a while that is as ill-perceived in Canada as President Bush. Canadians tend to be Democrats rather than Republicans." A recent headline in Maclean's magazine summarized the anti-Bush sentiment in Canada: "Canadians to Bush: Hope You Lose, Eh?" The headline drew much angry response from American readers but crystallized the discourse here about U.S.-Canadian relations.

"Interesting that Michael Moore and his 'Fahrenheit 9/11' has received such broad positive coverage in this country," Tim Powers, a Conservative Party strategist, said in a reference to a new documentary film critical of Bush. "There is a reevaluating of the current president that hasn't helped us here. The Liberals brought forward a campaign, as did the NDP, linking the Conservatives to the Republican Party. It's hard to compete against all these forces of branding."

Martin, 65, who began his term as prime minister promising to mend tattered relations with the United States, walked a fine line by trying not to appear to be too friendly with it. He consistently portrayed Harper as supporting the war in Iraq, U.S. values, privatized health care, repeal of gun control laws and increased military spending. "This campaign is about the Canada you want," Martin said on the campaign trail.

Liberal attack ads, showing photos of past Conservative leaders who cut social programs and education in Ontario, ran frequently on television and radio, with ominous voices warning Canadians, "Think Twice. Vote Once."

The ads were unleashed as the Conservative campaign made a series of missteps revealing that a contingent of hard-liners was active in the party, analysts said. Days before the vote, a documentary filmmaker released an interview with Randy White, a Conservative member of Parliament. White said the Conservatives would take steps to limit the rights of same-sex couples. He also said the judicial system, which has been active in reshaping social policy, needed to be reined in.

Martin and the Liberals capitalized on the documentary, saying it was evidence that the hidden agenda had been revealed.

The fear factor also played against the New Democratic Party, analysts said. They said voters favoring the NDP may have changed their minds at the last minute, voting for the Liberals to stop the Conservatives.

Roderick Robinson, 39, recalled a conversation with a Conservative candidate, saying he had asked the candidate about the party's position on immigration. "His response was, 'We are not against immigrants; however, our policy would be to look at bringing in skilled immigrants,'" Robinson said. "Those comments really concerned me immensely. I decided I would much rather vote Liberal, which I've never voted before."