The former Hostess Bakery in Biddeford, now occupied by Fedex Ground Services, has been sold to an investment firm for $12.4 million, according to a real estate brokerage involved in the deal.

The 265,000-square-foot building at 1 Baker’s Way, which once produced iconic snacks such as Twinkies and Sno Balls, was vacated in 2014, sold and then leased by Fedex in 2015. The buyer in that deal, Biddeford Holdings LLC, did extensive work to repurpose the building for Fedex.

This month, Biddeford Holdings sold the property to STAG Industrial, a Boston-based real estate investment trust. The seller was represented by CBRE|The Boulos Co., according to a news release issued Monday.

The sale was contingent upon Fedex, the building’s sole tenant, signing a long-term lease agreement, the release said.