THREE WALGREENS stores located in Roxbury and Mattapan were shut down for six days early in March because of extensive and long-running violations of the state sanitary code, but the pharmacies inside the stores were allowed to remain open.

Two of the stores were in Roxbury, on Washington Street and Warren Street, and the third was in Mattapan on Morton Street. All three stores failed earlier inspections, but this was the first time they had been forced to shut down while corrective actions were taken. The stores were closed from March 3 through March 9.

To make sure residents had continued access to prescription drugs, Boston’s Inspectional Services Department allowed the pharmacy in each store to remain open while the rest of the store was declared off-limits. Nothing aside from prescription drugs could be purchased, and inspectors spot-checked the store to make certain that requirement was complied with, according to Lisa Timberlake, a spokeswoman for the Inspectional Services Department.

Timberlake said the Walgreens closures were the first time a drugstore chain has been forced to close a store in Boston. A spokesman for Walgreens declined comment.

Health inspectors with the Inspectional Services Department primarily scrutinize restaurants, but officials can monitor  drugstores because they sell food items. The problems at the Walgreens stores came to the attention of the agency through social media posts, Timberlake said.

“All businesses operating in Boston must and will adhere to the Massachusetts state sanitary code for public safety,” said Jessica Thomas, assistant commissioner of constituent services, in a prepared statement. “A blatant disregard for complying with the sanitary code will not be tolerated.”

The presence of rodents was one of the primary sanitary code violations at the three Walgreens stores, according to inspection records.

For example, the inspector of the Walgreens store on Washington Street in Roxbury wrote: “Observed multiple rodent dropping[s] along chip/candy/and peanut aisle.” The inspector of the Walgreens store on Warren Street in Roxbury wrote: “Observed multiple bags of pet food gnawed in front retail area” and “Live mouse observed . . . and observed a bag of cheese it chewed into at last aisle.” And the inspector of the Walgreens on Morton Street in Mattapan wrote: “Observed dead mice on glue trap under the chip display.”

Other health code violations at the three Walgreens stores included dirty floors, dirty shelves, a dirty refrigerator, a dirty toilet, a sewage pipe leak, loose trash, and a walk-in cooler reading 79°F when it should be at 41°F or below.

Regarding the Walgreens  on Washington Street in Roxbury,ISD noted: “During the last year, inspectors have visited the property four times, all of which resulted in failed inspections. . . . In addition, inspectors made a startling discovery when they noticed a discarded needle cap on one of the shelves.”

The other Roxbury Walgreens and the Mattapan Walgreens  both failed two other inspections in the last year.