Walgreens is working with FedEx to launch a nationwide next-day delivery service for prescription drugs as the top pharmacy chains gear up to compete with Amazon.

Amazon bought online pharmacy PillPack in June, but the deal has not closed yet, giving Walgreens and its rivals the chance to head off a possible disruption in the pharmacy space.

Even before the e-commerce giant announced the acquisition, pharmacies had anticipated that Amazon would branch out into delivering prescription drugs. Competitor CVS rolled out its own delivery service for prescription drugs in June, just days before the deal.

Walgreens already offers same-day delivery in select markets, and the pharmacy chain will continue to expand that program next year.

The delivery service is part of Walgreens Express, which also lets customers preview the cost of their prescriptions and prepay for those that are eligible. Patients can pay $4.99 to have their qualifying prescription drug delivered as early as the next day or choose to pick it up in stores, checking out in a special express line.

"Next-day prescription home delivery is another convenience-driver, alongside our industry-leading number of extended hours pharmacies and one of the most downloaded digital apps in the category, designed to put care in the hands of our patients," Richard Ashworth, president of operations for Walgreens, said in a statement.

Walgreens and FedEx have already partnered to let customers pick up and drop off packages at almost 8,000 pharmacies nationwide.

WATCH: This small-rocket unicorn wants to be the FedEx of space