MUMBAI—One of the most challenging projects in the world is being attempted beneath one of its most densely packed cities.

If it works, Mumbai will become the planet’s most crowded metropolis to build an underground subway.

More than 8,000 workers and a fleet of 360-foot-long boring machines are working 24 hours a day—even through monsoon rains—to finish the 27-station, 21-mile subway through some of the world’s most densely populated neighborhoods, around the edge of one of Asia’s biggest slums, below an airport and under temples and colonial buildings to end at a green edge of forest where leopards still roam.

The train is also cutting a path through the country’s religious traditions, legal system and every layer of its society, with challenges at each stop.

The Mumbai Metro Rail Corporation Ltd.—a joint venture between the state and central government, which is building the subway—has had to negotiate with thousands of families and businesses to get them to move and has fought residents in courts over noise, land rights and even whether the subway will sully sacred ground.