O. Henry is known for his "twist endings," and the ending of "The Gift of the Magi" is probably the most famous of them all. At the end of the story Della cuts and sells her hair to buy Jim a chain for his watch, and Jim sells his watch to buy Della combs for her hair. Here we have a classic case of irony. The determination to find the perfect gift leads each character to make a sacrifice; that sacrifice makes each gift useless. The result is the exact opposite of what Jim and Della intended. What makes this ending so bittersweet is that it only comes about because they acted on their intentions: their gifts wouldn't have been useless if they hadn't given up their prize possessions. And since we follow only Della in the story, we don't know what has happened until the very end, during the exchange itself. It's the sudden, unexpected irony, which only strikes at the very end that makes the ending a twist.
Now that we've talked about what makes the ending a twist, let's ask another question: how do we feel about the ending? From one perspective, it's disastrous. Jim and Della seem much better off before the gift exchange. At the end, they have exchanged their most prized possessions to buy each other gifts that are now useless. Their original possessions – the watch and the hair – were valuable on their own. Not only that, their original possessions seem more precious because they were theirs – Jim's watch was a family heirloom passed down from his granddad, and Della's hair was literally a part of Della. Their gifts, on the other hand, are just new store-bought things that have no special connection to either person. Since each person wanted to buy the other the perfect gift, this means they have both failed colossally.
But then there's the narrator's perspective in that last paragraph, according to which the gifts they've given each other are the "wisest" gifts of all, the "gifts of the magi." If we agree, then of course they've succeeded in what they wanted to do. Both Jim and Della have shown that they're willing to sacrifice the most valuable thing they have to give something to the other. That makes their "useless" gifts incredibly valuable after all: the selfless love each feels for the other is embodied in those gifts. As long as they have the gifts, they'll be able to remember it. That kind of thing can't be bought. And it makes the gifts even more special and personal than what they replaced.
Which leads us to another point. Before the exchange, Jim and Della each had one prize possession. Each possession was valuable on its own and belonged to each person individually. The watch was Jim's, and the hair was Della's. Both possessions are sacrificed. In the exchange, each gains something new, which doesn't have any sentimental value as a token of their love for each other. That love isn't something they have as individuals, it's something they share together. So in the gift exchange, the two of them come closer together in a very concrete way.
Yes, endings can't get much sappier than this. But just admit it. Don't you love it anyway?