COLOMBO, Sri Lanka — In the days after Mahinda Rajapaksa, the Sri Lankan president, was betrayed by a group of his longtime aides, comparisons were made to Judas Iscariot and the serpent in the Garden of Eden, but nothing expressed the depth of the president’s hurt and bewilderment like the fact that the desertion had occurred just after a shared meal of hoppers.
As he watched his old allies begin to stage an unexpected campaign last month to block his re-election, Mr. Rajapaksa could not help but dwell bitterly on the hoppers, pancakes made of fermented rice flour that are one of Sri Lanka’s most beloved comfort foods. He praised his new health minister, who replaced the most prominent defector, by saying he was not “someone who eats hoppers in the night and then stabs you in the back in the morning.”
Mr. Rajapaksa is a famously sure-footed campaigner, so confident that hescheduled elections for Jan. 8, two years before the end of his second term. But the defections caught him unaware, and he is so jittery that he has begun promising concessions — like constitutional reforms and an investigation into possible war crimes committed during the government’s campaign against northern separatists — should he win a third six-year term.
At opposition rallies, crowds listen with fascination as the president’s former allies describe a “soft dictatorship” controlled by Mr. Rajapaksa and his relatives, who occupy dozens of top government posts. The defectors also brag about how they plotted under the president’s nose — through private group chats on a smartphone app, it turns out.
The challenge to Mr. Rajapaksa is being watched closely by officials in New Delhi, Washington and Beijing who view this island as a strategic foothold in contested maritime territory. Mr. Rajapaksa has steered his country closer to China, which has provided Sri Lanka with billions of dollars in loans for new ports and highways. India is especially wary of this trend, and in recent months has twice protested the appearance of Chinese submarines in a port in Colombo, the capital.
In a flush of popularity after crushing the northern insurgency, Mr. Rajapaksa removed the constitutional limit of two six-year presidential terms and dismissed the chief justice of the Supreme Court when she resisted his centralization of power. But it seems that he was less vigilant about the simmering dissent among men sitting beside him at cabinet meetings.
“They just thought that no one was going to be powerful enough to take them on,” Alan Keenan, a senior analyst with the International Crisis Group, said of the president and his family. “Now that the dam has broken, they are quite worried it will continue to break. Sri Lanka is a very political country. This kind of authoritarianism is quite a big shift.”
Visiting Sri Lanka ahead of the vote, one could be forgiven for thinking that there was only one candidate. Posters of Mr. Rajapaksa are plastered by the dozen on walls in towns and villages. At a rally for Mr. Rajapaksa in the town of Kuliyapitiya last week, 30 state-owned buses parked by the roadside and released a sea of people. Among the 20-foot cutouts of the president that towered over the crowd, one read, “President Today, President Tomorrow, President Forever You Will Be!”
One speaker at the rally, a former regional chief minister named Athula Wijesiri, said he could not think of any policy changes he would like to see in the president’s third term.
“Actually, we have no problems,” he said brightly.
Mr. Rajapaksa enjoys great popularity among the dominant ethnic group, the Sinhalese, Buddhists who make up around 70 percent of the population and who credit him with ending the 26-year civil war against rebels from the minority Tamil ethnic group in 2009. The postwar years have brought steady economic growth and a swift drop in the poverty rate.
But there is grumbling about the rising cost of living. Sampath Jayasundera, 33, a shop owner in Kuliyapitiya, said customers now ask for the prices of food items before buying.
“Little by little, people are forgetting about the war,” he said, “and as they forget about the war, other problems take precedence.”
Sumaru Wijesinghe, 46, a journalist at a pro-government newspaper, said Mr. Rajapaksa’s popularity was fading naturally as he approached 10 years in office.
“When you are in power for a long time, you can become a dictator,” he said. “People don’t like that.”
Any erosion is a risk for Mr. Rajapaksa. Because he has little backing from minority voters — Tamils resent the triumphalism around the end of the civil war, and Muslims feel alienated after brutal attacks by hard-line Buddhist groups — analysts say he needs at least two-thirds of the Sinhalese vote to be re-elected.
One central mystery remains: why leaders from Mr. Rajapaksa’s Sri Lankan Freedom Party, led by Health Minister Maithripala Sirisena, were suddenlywilling to risk taking on the president after standing by him for so long. Since late November, just after the president called for elections, 15 ministers, deputy ministers and legislators have left the governing coalition.
The most recent departure, on Monday, stripped Mr. Rajapaksa’s party of its two-thirds majority in Parliament, which allows it to pass nearly all legislation without opposition support. Over the last week, paid advertisements for the opposition candidates have begun to appear in newspapers and on television. Mr. Sirisena is now Mr. Rajapaksa’s main challenger for president.
Former Fisheries Minister Rajitha Senaratne, a friend of the Rajapaksa family for more than 40 years, said a core group of party leaders had planned to defect in secret — swapping their telephones for ones they trusted not to be tapped, speaking in code and via group chats on Viber, a mobile app.
As soon as news of the defections went public, he said, the president “was talking to my wife every hour, trying to influence her.”
“It was painful for me, also, leaving a friend,” he said. “But he changed himself totally after the victory over terrorism. He was a wonderful person earlier. He used to listen to everyone.”
These days, he said, Mr. Rajapaksa is “trapped by his family.”
Mr. Senaratne said the opposition drew its inspiration from Narendra Modi’s campaign for prime minister in India, which tapped into a reservoir of frustration with the ruling Nehru-Gandhi family. He said opposition campaigners had received advice from firms that worked on Mr. Modi’s campaign, although they had not received any funds from foreign governments.
“I think even India would like to have another government” in Sri Lanka, he said, “where they would have another understanding” with the country’s leaders.
At his appearance in Kuliyapitiya, Mr. Rajapaksa was his usual self, all belly laugh and toothy smile. He began his stump speech by celebrating his victory over the Tamil rebels, making only the most opaque reference to his challengers. (“We will not allow them to destabilize the country, as they did in Libya, Syria and Egypt.”) Keheliya Rambukwella, the media and information minister, said the opposition campaign was misreading public opinion by focusing on Mr. Rajapaksa’s family members.
“Just because the president has relatives who are qualified, should they go outside of the island and work somewhere else?” he said. “Where is the rationale for that? This is all propaganda. Unfortunately, the president has quite a lot of relatives who are very highly qualified.”
He described Mr. Rajapaksa as hurt, but not surprised, by the defection of his lieutenants, whose loyalty he said had been the subject of rumors for months. The president’s eldest son, Namal, used more pointed language, calling Mr. Sirisena “the man that dissected a piece of faith I had in mankind.”
“Like the snake that betrayed Eve in the Garden of Eden, or rather like Judas that betrayed his men after the Last Supper,” he wrote in a blog post, “without a word of warning he switched sides, faster than a chameleon changing his color.”