My adviser agreed to write a letter of recommendation, but hasn't done so
First point: what your professor is doing is absolutely not OK. There are valid reasons to back out of writing a recommendation letter late (illness, family emergency to name a few), but what he is doing is intentionally sabotaging your PhD applications.

Second: ask for a meeting with your advisor, where you can have some uninterrupted time to explain your motivation for wanting to go elsewhere for your PhD. Focus on things like wanting to diversify your interests, work with a large variety of people, maybe work on a research project that is not available at your school. Feel free to add in things like how working with him has helped you realise how many opportunities are out there and prepared you to undertake studies at insert name of university you are applying to. Ask him if he could write you the recommendation letter and tell him that when you have your acceptances you will make a choice of where to go, and you will not rule out your current institution until you have all the answers. Explain that you feel that he is limiting your options, and feeling shut in is not a good place to be when you are trying to make serious decisions about your future. In short, flatter him and the current programme, explain your motivation in a way that doesn't come off as "this place sucks" and hope for the best. Keep the tone of this conversation calm and non-confrontational. You don't want to destroy your last few months there, and even if he says no, thank him for his time and explain calmly that you hope he understands why you will still go on with the application with another recommender, and that you hope there will be no hard feelings between you.

If this doesn't work I would go to the professor that knows you the second best in your master's program, or maybe even from your undergrad, and explain the situation to them (confidentially) and ask if you can get a letter of recommendation from them instead on short notice. It will probably be seen as a little strange that your advisor isn't writing you a letter of recommendation, but at that point it's your best option.