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 he scheduled 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.