Walgreens is spending nearly $1.2 billion to build its stake in AmerisourceBergen, the pharmaceutical wholesaler that supplies its drugstores, mail order and specialty pharmaceutical businesses.

The nation’s largest drugstore chain says it will own a 15 percent stake after exercising warrants to purchase 22.7 million shares.

Walgreens Boots Alliance Inc., based in Deerfield, started building that stake in 2013, when the companies entered a 10-year supply agreement. Walgreens still holds warrants to buy another 22.7 million shares in the Chesterbrook, Pennsylvania, company.

Walgreens runs more than 13,000 drugstores in 11 countries. It plans to boost that total by buying rival drugstore chain Rite Aid Corp. for more than $9 billion, a deal expected to close later this year.