Somewhat alike. A compulsion is a repetitive behavior that is in response to a thought or urge. The implication is that it is powerful and very difficult to resist. Compulsions can be unwanted or intrusive and tend to feel out of control.
It's the intensity. Of the distress. A compulsion (behavior) or obsession (thought) comes with intense anxiety & distress. Wanting something really badly or having a goal usually feels more positive and motivating & is something you think is good for you. If you get what you want, you feel good. A compulsive action is never satisfying, it just keeps repeating & the distress continues.
Function! All of us at times want something "badly". How we get it, or how we try to get it and don't succeed but keep trying- no matter the cost in time, money and any destruction it causes to our lives-is the difference. Generally compulsions carried to extremes drive us to do the same thing again and again and expect the results to change. That's a malfunction!