Walmart has agreed to acquire the men’s clothing company Bonobos for $310 million.

The purchase is part of a sweeping effort by the world’s largest retailer to revamp its business model as it tries to better compete with Amazon, which on Friday announced that it would buy the upscale grocer Whole Foods for $13.4 billion.

Bonobos, founded 10 years ago in New York, began by selling simple chino pants on the internet. In recent years, it has expanded to offer shirts, suits and other men’s clothing, and has opened dozens of brick-and-mortar locations, as well as boutiques in Nordstrom department stores, a previous investor in the start-up.

Yet even as Bonobos has become a more conventional retailer, it has maintained its online ethos, offering generous shipping and return policies and calling its customer-service agents ninjas. Even its stores have a twist — customers are fitted on site, but the clothes are later mailed.

This sensibility, and Bonobos’s sustained growth, are what attracted the interest of Walmart.

Walmart is working aggressively to transform itself into a dominant force in e-commerce. When the company bought Jet.com last year for $3.3 billion, it installed the Jet founder, Marc Lore, to lead its e-commerce efforts in the United States and gave him a mandate to expand quickly.