I would say that the ending was a good surprise. This is one of the reasons the short story is such a success and a classic.
There are a few things that make the story a surprise. First, what is underlined right from the beginning is their poverty. In fact, the opening sentences show their poverty:
"One dollar and eighty-seven cents. That was all. And sixty cents of it was in pennies."
This leads the reader to expect a sad story. Second, the fact that each had only one thing of worth - Jim, his watch, and Della, her hair - also underlined their difficult situation. In other words, the reader does not know or anticipate that they would give these prized possessions away to buy a gift for each other. So, I would say that the story offers a surprise ending, which is heart-warming.
Now, if we read the story a second time, we can see the clues that O. Henry left. For example, the emphasis on Della's long hair and Jim's watch foreshadows what might happen. But this is only because we know the end of the story. Without knowing the end, we would not come to these conclusions.