Hershey's chocolate bars are shown in this photo illustration in Encinitas, California January 29, 2015. REUTERS/Mike Blake/File Photo

(Reuters) - Hershey Co HSY.N said on Wednesday it would buy Pirate Brands from B&G Foods Inc BGS.N for $420 million in an all-cash deal, giving the chocolate maker rights to snack brands such as Pirate's Booty, Smart Puffs and Original Tings.

The deal is expected “to be accretive” to Hershey’s financial targets as the company delves into the more than $2.5 billion cheese puffs market, Hershey said in a statement.

Hershey has been diversifying its business by adding more snacks to its portfolio as more American consumers opt for healthier snacks over sugary candies and chocolates.

Last year, the Kisses chocolate maker bought Amplify Snack Brands for $921 million, helping it expand its range of offerings, adding products such as SkinnyPop popcorn and Paqui tortilla chips to its portfolio. Hershey also bought beef jerky maker Krave in 2015.

Pirate Brands, which B&G Foods bought in 2013, will operate within Hershey’s snack unit Amplify.

B&G Foods said it would use the net proceeds from the sale for repaying its long-term debt and funding possible acquisitions.

Hershey intends to finance the transaction with cash reserves as well as short-term borrowings and expects the deal to close in the fourth quarter of 2018.

After the deal was announced, B&G Foods rose nearly 1 percent to $32.15 and Hershey shares were inactive in after-hours trading.