For example: is this for personal reasons? estate planning purposes? to get out of an upcoming compliance obligation? to avoid having to invest more in the business? to have a more liquid asset base? to become part of a larger company? because this line of business isn't really a good fit with other things that the party has going on?
There are lots of reasons, not all of them good. Sometimes there is intense pressure on public companies to increase their earnings per share every year. You can artificially boost those numbers by acquiring someone successful, so that when you fold it into your numbers, it looks like you were more profitable than you were. That's a potentially detrimental focus on the very short term, at least some of the time.
Anyway, once we've got a deal, the parties' interests generally diverge. They agree that they want to minimize disruptions to the seller, but the seller basically wants to maximize after-tax profits. The seller might worry about the culture of the buyer.
Sometimes a seller will go through an investment banker to find prospective buyers, or even run an auction for the company. But of course, they'll want a fee.
Once you've got the agreement in principle, the buyer begins due diligence investigation: material contracts to which the seller's company is a party (will everything have to be renegotiated, will favorable pricing terms evaporate, etc.?).
When the merger plan takes effect, by operation of law the ABC+XYZ entity, in the name of ABC (usually) simply assumes all the assets and liabilities of XYZ: title is automatically vested in ABC, etc. And it also specifies what happens to shares of XYZ: do we convert it to stock in ABC, or buy them out in cash, etc. This is a nice simple way to structure an acquisition, unless you're talking about a publicly-held company, because the shareholders have to approve the deal and that's time-consuming and expensive, plus there's the SEC to worry about.
And note that there are triangular and reverse-triangular mergers (target merges with a subsidiary). Plus, there's something called a "consolidation," in which neither constituent corporation actually survives... this is rare, though.
So why do things this way? It might be advantageous from a tax perspective (this is usually the reason people pick one structure for a deal), but there are other good reasons. For example, you can cherry-pick what assets you want, plus maybe you don't want all the liabilities (known or unknown) that you'd get via merger, or maybe you don't want the people, just the stuff. So asset purchase is more flexible than merger, because you can pick and choose what you transfer. Buyers buy assets in order to avoid liabilities-- they can't always disclaim all of them, though (courts have found "constructive merger" from time to time, so want to be on the lookout for an asset purchase that looks too much like a merger).
If the target is a public company, this is a "tender offer" (we are making an offer of $x/share, and this price is contingent on shareholders tendering y% of shares). There are hostile tender offers all the time. Shareholders "vote with their feet:" they say yes or no based on whether the price is favorable or not.
Sales of stock don't have to be unanimous, either, which is kind of nice, although you might be annoyed to have a minority shareholder: you can kill the deal in that case, or maybe state law will allow you to squeeze them out.