NEW DELHI — No flights. No trains. Only essential services open. More than 1.3 billion people urged to stay in their homes.

India, the world’s second most-populous country, is making a dramatic, last-ditch effort to prevent an explosion of coronavirus cases in a country ill-equipped to handle such an outbreak.

For the next 21 days, there will be restrictions on commerce and movement across the length and breadth of India. Even at the height of its battle against the virus, China did not impose a nationwide lockdown.

On Tuesday, India had about 500 confirmed coronavirus cases, but the number is growing rapidly. Testing remains limited, and there are signs that the virus could be spreading undetected.

In a speech Tuesday night, Indian Prime Minister Narendra Modi made clear that the country was at a crucial juncture. “If we don’t manage these 21 days, the country will be set back by 21 years,” he said.

His emotional appeal to citizens not to step out of their homes did not include specifics about how they would meet basic needs. That immediately provoked frantic buying at grocery stores, which remain open as essential services.

Less than an hour after his speech, Modi wrote in a tweet that there was no need for panic and that authorities would ensure access to food and medicine.

In his speech, Modi also acknowledged that the measures — an extension of steps already announced by various states — will exact a cost. “We will have to pay a heavy economic price for this, but lives are more important,” he said.

Large, densely populated countries such as India will determine “the future of this pandemic,” Michael Ryan, executive director of the World Health Organization’s health emergencies program, said Tuesday. It is “exceptionally important” that India take aggressive steps to contain the spread of the virus, he said.

On Sunday, India shut down the backbone of this sprawling nation: a network of trains that crisscrosses the country, carrying rich and poor, commuters and vacationers, with 23 million passengers a day boarding 13,500 trains at more than 7,000 stations.

The sudden decision to suspend all passenger trains and interstate buses left thousands stranded as states and cities began to enforce prohibitions on gatherings of more than four people.

Among those stuck were Sanjay Kumar and his father, Ashok, both daily wage laborers. They had been trying for two days to travel from Delhi to their home 420 miles away. They made it as far as Lucknow, the capital of Uttar Pradesh, India’s largest state, only to find that all of the trains were canceled and almost no shops were open.

His father had a fever, Sanjay Kumar said, and the two men were running out of money. The police, charged with implementing the lockdown measures, admonished them to get off the streets. “I think the virus will kill us all,” Kumar said as he tried to hitch a ride from a passing truck or bus.

In Hyderabad, a metropolis in southern India, nearly 300 seasonal construction workers were trapped with no way to reach their homes about 400 miles away. Chakradhar Buddha, an indigenous rights activist in the city, said the group was running out of food. The workers did not “anticipate the total breakdown of transport,” Buddha said. “Now they are anxious and scared.”

In its race to slow the rate of infection, India is delivering an economic shock that will jeopardize livelihoods, producing another urgent challenge.

The current measures will have a “massive economic impact,” Kaushik Basu, former chief economist of the World Bank, said in a recent television interview. “We have to prepare for that.”

Even if India manages to avoid a deadly surge in infections, there is a strong chance the country is facing “several months of pretty depressed economic conditions” that will lead to a “severe livelihood crisis,” said Amit Basole, an economist at Azim Premji University in Bangalore.

The vast majority of the Indian workforce doesn’t have a steady job or ready source of savings, added Basole. “They’re basically going to see their incomes dry up,” he said.

Basole and other economists and activists are urging the Indian government to take steps to help the poor, including through emergency cash transfers and three months of free food supplies. The government has promised that a package of relief measures is coming but has not released any details.

Economists struggled to quantify the dislocation caused by the fight against the pandemic. “It’s extremely difficult to assess the economic implications of such a nonlinear event,” said Dharmakirti Joshi, chief economist at Crisil, an Indian ratings agency.

The effects of the lockdown are already rippling through the economy. Several major car manufacturers including Renault, Hyundai and Honda Motor have closed down factories in India at least through the end of the month.

The decision to shut down the railways is without precedent, said Arunendra Kumar, former chairman of Indian Railways. The last time the system closed was during a strike in the mid-1970s, he said. Even during times of war, strife and famine, there was not a nationwide stoppage.

“Never in my dreams could I have imagined a situation in which stopping trains would be to our credit,” said Kumar. But “this virus does not see if you’re going by train or by road or by air. It looks at your negligence and capitalizes on that.”

At Lucknow’s Malhaur railway station, normally a chaotic crush of travelers, vehicles and vendors, there were only a few stray dogs and a clutch of policemen guarding the barricaded entrance Tuesday. Birds chirped in the stillness.

“I’ve never seen such silence,” said Shubhankit Gupta as he surveyed the scene. Gupta runs a small cafe near the station that is now shuttered. “Of course, our business is suffering, but life is precious,” he said.

Saurabh Sharma in Lucknow contributed to this report.