By Sarah Nassauer

Walmart Inc. is selling its Indian stores to Flipkart, the e-commerce startup it controls, consolidating its operations in the world's second-most-populous country as it works to fend off Amazon.com Inc.

Walmart operates 28 warehouse-club-style stores in India that are only open to members. Branded as Best Price Modern Wholesale, the stores serve independent retailers and other small businesses. Indian regulations prohibit Walmart from operating supercenters or selling its own inventory directly to consumers through its websites.

Flipkart will buy Walmart India, adding the wholesale business and around 5,200 employees to its e-commerce and other operations, creating a Flipkart Wholesale business later this summer, Walmart said. A Walmart spokesman declined to share financial terms of the deal.

In 2018 Walmart bought a roughly 77% stake in Flipkart for $16 billion--the U.S. giant's largest-ever acquisition. Last week Walmart said it led another investment round in the startup for $1.2 billion, raising Flipkart's valuation to $24.9 billion. Walmart's stake in Flipkart increased after the investment round, said a person familiar with the situation.

Amazon is also pushing aggressively to grow its business in India, investing billions of dollars to compete.

But both American behemoths have bumped up against regulatory hurdles in the country, as well as the challenge of navigating a fragmented retail space made up primarily of small, independent retailers.

Soon after Walmart sealed its investment in Flipkart, India altered its rules for online sales by foreign-owned retailers, forcing Amazon and Walmart to rewire their supply chains. The rules don't apply to local rivals.

Flipkart aims to use Walmart's wholesale business to work more closely with independent retailers in the country, offering more products and services such as financing, the company said. Walmart India CEO Sameer Aggarwal will remain during a transition period, then move to another role within Walmart, the company said.

Walmart opened its first membership-based wholesale outlets in India in 2009, with hopes it would eventually be allowed to open stores available to all shoppers.

Walmart, which had $520 billion in net sales globally last fiscal year, doesn't break out sales from India, which is a small part of its international operations. The country is included with Africa, South America, Japan and other international markets that generated a collective $28.5 billion in net sales last fiscal year.

The U.S. giant has been revamping its international operations, selling its e-commerce operations in China in 2016 to JD.com, selling 80% of its Brazil store business in 2018 to a private-equity firm, and most recently reviving efforts to find a buyer for its Asda grocery-store chain in the U.K.

Write to Sarah Nassauer at sarah.nassauer@wsj.com