Okay it seems like you want to keep this job so that's step one. The goal here is to keep the job. Now just arrange the chess pieces to accomplish your goal. Here are two things I would keep in mind:
1. Do exceptionally good work for the next 30 days. Bust Your Ass. Most likely this is his way of reasserting his superior status over you since you went out of line. You need to show him that he's the master and you're the subordinate. The best way to do that is to bust your ass and do the work the way he's dictated that he wants the work done. Don't do this passive-aggressively or in a desperate way, do this with determination, with purpose, authentically. Like you were born and live to serve him. Once you've pleased his ego, he'll have a harder time rationalizing firing you.
2. DO NOT COMPLAIN TO HR/LEGAL. Only say good things about your boss and how's he's so intelligent and you really respect his leadership and blah blah. Swallow your pride and openly acknowledge his criticisms of you and say this whole process is helping you grow as a person and be better. Repeat: DO NOT COMPLAIN TO HR/LEGAL NO EXCEPTIONS IT DOES NOT MATTER IF YOU THINK THEY ARE YOUR FRIEND. If you have negative things to say about him/the company, they will begin their campaign to disarm you and support the decision to let you go.
On a meta-note. I think you should actually leave the company and find a company/manager with a supportive culture. By staying at this company you are stunting yourself. You seem too dependent and fearful and that is a recipe for life-long stress and anxiety, both of which will ultimately kill you. Improve your independence and self-reliance, find another job.
I've hired and fired many people and I can tell you that getting fired is not that bad. Companies know there are bad companies and that personalities don't always mix. What matters most to a potential future employer is not if you've been fired but if you can actually do good work and you fit in. If you do good work and there are companies where you can fit in, you don't need to fear being fired from anywhere. You'll find your place.