The landmark ruling lays partial blame for the opioid abuse epidemic on pharmacies that supplied the drugs.
Walgreens is based in Deerfield, Illinois, and operates more than 9,000 stores in all 50 states.
The company said it will offer commonly prescribed medications with discounts to its Prime members.
Twitter users were definitely down with this unintended collaboration.
The company said it will close 150 Walgreens-run clinics by the end of the year, but it will keep open more than 200 that are run in partnership with health care providers.
The stores are the latest to stop selling the products as health officials probe a nationwide outbreak of lung illnesses and deaths.
Walgreens, CVS and Wegmans have joined similar calls from Kroger and Walmart following multiple mass shootings in recent weeks.
The pharmacies are accused of failing to stop opioid orders that were suspicious or of an unreasonable amount.
The refusal came after Nicole Arteaga's doctor told her that her unborn baby no longer had a heartbeat.
How to plan the perfect barbecue for Memorial Day — or any summer Saturday — if you struggle with acid reflux.