Ralcorp shareholders will receive $90 per share in cash, a premium of 28.2 percent to the stock's Monday close, ConAgra said in a statement.
ConAgra, the maker of Chef Boyardee pastas and Slim Jim meat snacks, began its pursuit of Ralcorp in March 2011 with an offer of $84 per share.
The company raised its bid twice but Ralcorp spurned them, including the then-final offer of $94 per share, which valued Ralcorp at $5.2 billion.
Ralcorp chose instead to spin off its cereals business into Post Holdings earlier this year.
With Tuesday's deal, the combined market value of Ralcorp and Post is about $6.12 billion, showing that Ralcorp was able to extract a much higher price than last year's bids.
Davenport & Co. analyst Ann Gurkin said ConAgra did not overpay since the deal would result in a very lucrative private label business.
"Ralcorp with ConAgra's private label portfolio will make a very strong combination," Gurkin told Reuters, adding her main concern about the deal was successful and timely integration.
ConAgra said the acquisition will create the largest private label packaged food business in North America, with about $4.5 billion in combined annual sales of store-branded products.
ConAgra's hares were up 6 percent at $29.93 before the bell on Tuesday, after closing at $28.29 on the New York Stock Exchange on Monday.
Ralcorp shares were trading at $88.50. They closed at $70.23 on Monday.
The deal is a big win for activist investor Corvex Management, Ralcorp's largest shareholder, which in August demanded that the food manufacturer either sell itself, buy another company or change its strategy after a series of earnings disappointments.
Ralcorp reported on Tuesday a fourth-quarter net loss of $44.2 million, or 80 cents per share, on revenue of $1.07 billion.
The deal is valued at $6.8 billion including debt, ConAgra said. The deal, which was approved by the boards of both companies, will add to earnings in the first year, ConAgra said.