The acquisition, first reported earlier in the day, would combine two of the largest U.S. drugstore chains. The price represents a 48 percent premium to Rite Aid's closing price on Monday.
The deal's total enterprise value is $17.2 billion, including acquired net debt. The companies expect it to close by the second half of next year.
"This combination will generate a stronger base for sustainable growth and investment into Rite Aid stores, while realizing synergies over time," said Walgreens Boots Alliance CEO Stefano Pessina in a statement.
Many companies in the industry have looked to cut costs in recent years amid changes like the Affordable Care Act.
Walgreens said it expects synergies of more than $1 billion from the deal. Rite Aid stores will initially operate under the same name as a wholly owned subsidiary.
Walgreens had net sales of $76.4 billion in fiscal 2014, accounting for about 20 percent of the retail prescription drug market. Rite Aid had prescription drug sales of $18.1 billion in fiscal 2015, up from $17.2 billion in the previous year.
Rite Aid shares closed more than 40 percent higher Tuesday after reports that a deal could be imminent. Before the spike, Rite Aid had a market capitalization of about $6.4 billion.
Walgreens and CVS shares also climbed Tuesday.