Prime Minister Narendra Modi entered India’s general election projecting supreme confidence. “Ab ki baar, 400 paar” went his party’s slogan, meaning this time his side was gunning to surpass 400 seats in the lower house of Parliament, a staggering majority.

But as the seven-week voting period enters its final stretch, with results expected on June 4, India is witnessing something unusual from its powerful leader. It is seeing him sweat.

As Mr. Modi crisscrosses the country for rallies in 100-degree heat, he has often appeared on the defensive, and sometimes rattled. He has frequently set aside his party’s main campaign message — that India is rising under his leadership — to counter his opponents’ portrayal of him as favoring business and caste elites. He has resorted to stoking anti-Muslim sentiments to fend off attempts to split his Hindu support base, only to deny his own words later.

Mr. Modi’s Bharatiya Janata Party, or B.J.P., is still a heavy favorite. But it is finding that the political opposition, counted out after big losses to Mr. Modi in the previous two national elections, has some fight left in it.

The opposition has found traction in challenging Mr. Modi’s control over the national narrative. With the broadcast media cowed by him, opposition leaders have turned to online platforms to find an audience for a pitch focused on economic and social justice, painting the prime minister as a primary culprit in India’s growing inequality.