Redwood Shores, California-based Oracle will buy Sun shares for $9.50 each in cash. The price represents a 42 percent premium to Sun's Friday closing stock price of $6.69. Net of Sun's cash and debt, the transaction is valued at $5.6 billion, Oracle said.
IBM had offered to buy Sun for $9.40 per share, but acquisition talks fell apart earlier this month. Sun balked at the price and canceled IBM's exclusive negotiating rights, leading IBM to withdraw its offer.
Oracle expects the purchase to add at least 15 cents per share to its adjusted earnings in the first year after the deal closes. The company estimated Santa Clara, California-based Sun will contribute more than $1.5 billion to Oracle's adjusted profit in the first year and more than $2 billion in the second year.
Sun, which invented the Java programming language used to develop applications for Web sites and mobile phones, has been reluctant to sacrifice its independence, even as it reports big losses. Despite billions in sales - $13.3 billion over the last four quarters the company has not been able to turn a consistent profit, losing $1.9 billion in the same period.
Analysts have long said the company can not stand on its own and many were skeptical the company would be able to find another buyer after talks with IBM broke down.
The IBM talks may have been derailed by antitrust issues since the two companies overlap in several areas. In tape-based data storage, for example, together IBM and Sun would hold 52 percent of a $3.1 billion market.
The companies had been working out the terms of a commitment from IBM that it would see the deal through even if antitrust regulators raised objections.
The deal with Oracle may not be plagued by the same antitrust issues, since there is significantly less overlap between the two companies. Still, Oracle would be able to use Sun's products to enhance its own software systems.
Oracle's main business is database software. Sun's Solaris operating system is the leading platform for that software. The company also makes "middleware," which allows business computing applications to work together. Oracle's middleware is built on Sun's Java language and software.
The transaction has been approved by Sun's board of directors. Oracle expects to close the deal this summer.
Shares of Sun jumped $2.46, or 36.8 percent, to $9.15 in premarket activity while shares of Oracle fell 68 cents, or 3.6 percent, to $18.38.