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 greates tresures 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. Of all who give gifts these two were the wisest. Everywhere they are the wisest. They are the Magi.
In a rather unorthodox manner for story writers, O. Henry overtly states his theme--almost preaches it. This theme reiterates the quotation in the question. O. Henry does this to underscore the paradox of how sacrificing is wise, since doing so goes against man's basic instinct of self-preservation to look out for himself. The allusion to the Magi who came to see the Christ child extends to love as defined in the gospels of Christ: "Greater love hath no man than this, that a man lay down his life for others." [John:15:13]
Love as willingness to put the needs of another above one's own is the theme of O. Henry's "The Gift of the Magi." Although Della knew that "had the Queen of Sheba lived in the flat across the air shaft," she could have hung her hair out the window to dry and "depreciate(d) Her Majesty's jewels and gifts" with the beauty of this hair, she has not hesitated to sacrifice it to idea of making her husband happy with a new watch fob. And, although Jim, could have pulled out his watch and watched King Solomon "pluck at his beard from envy" if he were "the janitor in the basement," Jim, too, willingly--and "foolishly" sells his watch in order to delight his beloved Della with combs for her luxurious hair. The beauty of O. Henry's story is that the characters, the "foolish children" of his story, understand the wealth of the spiritual value of true love. And, it is for this reason that he calls them the Magi.
The idea shown in the quote you cite is the main idea of this short story. We can see it demonstrated in what Jim and Della do for one another and how that makes them feel.
In this story, Jim and Della end up sacrificing for one another. Each of them gives up his or her prized possession in order to buy something nice for the other. Of course, by doing this they make the things they buy useless (Jim can't use the watch chain since he pawned the watch, for example).
Because they have done this, the things that they have bought are worthless, right? You would think so, but that is clearly not the case. After they find out what they have done, they love each other just as much (possibly more) than they had before. The reason for this is that they have both shown that they care for, and will sacrifice for, the other person.
In a relationship, you must care for the other person and you must care for them enough to sacrifice (at times) for them. If you do not, your relationship will not last.