This excellent tale is normally taught as an example of situational irony, when the last thing we expect to happen actually happens, and we grieve with Jim and Della over the irony of what has occurred. However, it appears that apart from this, O. Henry had another purpose for writing the tale, as is made clear in his final paragraph, where he discusses the relevance of the title of this story to the action as a whole. According to the narrator, the real "gift" in this story is the kind of love that inspires radical sacrifice and intense generosity, as demonstrated through Jim and Bella and their love for each other.
Thus it is that the narrator discusses the identify of the Magi and how they set up the tradition of giving gifts and then relates it to his tale:
And here I have lamely related to you the uneventful chronicle of two foolish children in a flat who most unwisely sacrificed for each other the greatest treasures of their house. But in a last word to the wise of these days, let it be said that of all who give gifts, these two were the wisest... They are the Magi.
So, even though we may laugh at the unfortunate turn of events that lead Jim and Bella to sell their most precious possession to buy something for the other to use with their most precious possession, according to the narrator, it is the spirit behind the gift giving that makes them closest to the original Magi and the original spirit of present giving. This is the purpose of the tale, as the author challenges us and the generosity behind the gifts that we give.