Wal-Mart Stores Inc. , the world’s largest retailer, has agreed to pay $40 million to as many as 87,500 current and former employees in Massachusetts, the largest wage-and-hour class-action settlement in the state’s history.

The class-action lawsuit, filed in 2001, accused the retailer of denying workers rest and meal breaks, refusing to pay overtime, and manipulating time cards to lower employees’ pay. Under terms of the agreement, which was filed in Middlesex Superior Court yesterday by the employees’ attorneys, any person who worked for Wal-Mart between August 1995 and the settlement date will receive a payment of between $400 and $2,500, depending on the number of years worked, with the average worker receiving a check for $734.

“The magnitude is large - it’s bigger than most settlements paid in wage-and-hour cases,’’ said Justin M. Swartz of New York-based law firm Outten & Golden LLP, who has handled similar cases, including a pending case against Wal-Mart. “But you would expect it to be bigger since Wal-Mart is the biggest retailer.’’

Under the terms of the settlement, neither side is allowed to comment. But in an affidavit filed with the settlement, the lead counsel for the employees, Philip Gordon of Boston’s Gordon Law Group, said the accord “dwarfs settlements of similar class actions against Wal-Mart across the country.’’

“For many employers, this settlement will serve as a reminder to take the payment of earned wages and benefits seriously. For many other employers, it will provide comfort that all Massachusetts businesses must operate on a level playing field,’’ Gordon wrote in the affidavit. “But most importantly, for employees of Wal-Mart, it finally pays them their earned wages and it puts in place systems and processes to ensure that abuses like those alleged never happen again.’’

The Massachusetts case is similar to many others that have been brought against the retail behemoth by employees across the country, most alleging that the Bentonville, Ark.-based company violated laws by requiring employees to work through breaks, to work beyond their regular shifts, and similar practices. Wal-Mart has denied the allegations, but in December, the merchant agreed to pay up to $640 million to settle 63 federal and state class-action wage-and-hour lawsuits.