These situations are a rock and a hard place OP, but I don't think what you did was wrong. It seems like your friend was giving you a lot of his negative energy over the years, so it is not surprising that at some point it might cause a spark. It seems to be that context plays a pretty important role in people staying in a mental loop. for instance, different factors act as enablers for people to keep going in certain mindsets and ways of doing. Whether it is staying with his parents, job, girlfriend. You are right to point these things out to him, and it seems like you have said them before in a more diplomatic manner. As others have said though, change does require some inner acceptance and motivation in most circumstances. You can support him, but if he isn't ultimately willing to change or stuck in such mental loop, you are not going to see much immediate impact.
On the other hand, things can perculate with time. It is obvious he took it to heart, and I don't think that is a bad things. I am also a firm believer that in some instances, people just don't know how to enact what is best for them, and that has a big social effect as well. So it is in their friends interests for them to change certain aspects of themselves, otherwise it can be intolerable to spend much time with them. For instance, if there own behaviour isn't making them happy at all, then that needs to change. I think our mentality is often quite plastic, but can take a lot to shift.
Those reacting harshly on the OP: He has known this friend for years and finally exploded. He obviously seems to care about him. Why only have compassion for one side of the story? I mean this is one side of the story, but from this it sounds like his friend has been giving negative energy for years. Sure, there is a reason for that which we should have compassion for, but it is still a negative traight that can make others feel bad. For instance, I am someone who has pretty firey anger, and that is something I threw out to others, especially my dad, and he tended to absorb that energy. It is not always a one way process of being a victim or a purpatrator. Relationships are often more complex. That being said, in many cases with mental issues, you absolutely cannot expect just to solve another persons problem. I don't think the OP was of that mindset though. Shit just hit the fan, as they say...which it does sometimes.
Speaking from experience, I can say the "tough love" stuff didn't help me at all. Only things it did is made me feel worse about myself and strained the relationship I had with this person even more than before. This person also violated my trust and privacy to "help" me and you can probably imagine how well that went.
I only changed/continue to change because I chose to. It took me a long time to due to my issues but I got there on my own and still have a long way to go.
I think to say others didn't have an impact on your change is likely a bit simplistic. For instance, what made you choose at one point rather than another? Whose to say that his actions didn't have an affect, just not the determinative shift when he was hassling you?