It has nothing to do with selling resources; it has everything to do with who owns what stocks and the order in which you buy other players.
My stock price was in around the $66, and the other guy was around $30. He owned a good chunk of my stock and I his, his buyout price to me wasn't much different than mine to him.
It sounds like he had about half your stock, and that gave him the edge he needed to win the race, especially since you used a lot of time and money buying everyone else and he just saved money for the final buyout instead.
The key to winning in such situations is knowing that when buying someone, you not only get their buildings and claims, but all their stock as well. If you own half your stock and someone else owns the other half, buy him first before everyone else, because now you will own all your stock, making it incredibly difficult for any other players in the game to get enough money to buy you.
Smores brings up another pitfall when buying. If player A has some of player B's stock, and you buy player B, then some of the cash that you used for the buyout will go to player A. Perhaps in your case, you might have bought player B for $200,000, but player A had half his stock, in which case, half of the buyout money ($100,000!) goes to player A, giving him a head start in the final race. Again, it's important to buy someone who has a lot of stock. If you instead just buy player A first, you now get his shares in player B, so his stock will work for you instead of against you.