Adviser wants to be joint first author, even though I did most of the research In my research, my adviser only gives minimal advice that is limited to the direction of the research and defining the problems. 

I can say I do most of the thinking, the actual solutions of the problems. 
Even at one time I needed to explain to my adviser how my algorithms work.

The only "effort" my adviser does is writing the actual paper, since I'm still a master's student and lack experience of writing. Moreover, I'm not a native speaker so I'm still trying to improve my English writing.

Well, that's the intro of my background. FYI, I'm a CS student and I'm aiming to publish a paper in a conference in ACM.

The actual problem is my adviser demands to be joint first author.

I asked the reason and the reply was it was needed to progress to associate professor, with my help, and eventually gain tenure.

I suspect that the supervisor feels  under risk to be kicked from the university. With 3-4 years as an Assistant Professor but doesn't really have good research output (only 1-2 small papers every year).

I reluctantly agreed to assist under these considerations:

1. We can be joint first author but my name should be written first. Initially wanted their name to be written first because alphabetically the last name comes first compared to my last name.
Then I did a "bargaining" by saying that I want to be researcher in the future and I need my name to be put first.
The discussion ended and I was allowed my name to be written first.

2. I need to graduate
In my university, advisers have total control to let students graduate. 

With this post I want to ask you for more suggestions.

Edit 1:
Right now I want to play "safely" rather than being kicked out, but I feel I'm being treated a bit toady. Usually the adviser likes to scold other students.

Edit 2:
The advisor does indeed write the most part of the paper, but it doesn't mean that I didn't take any part in the writing. I tried to write an initial paper, from the introduction to technical part, writing equations, making figures, producing results, etc. 
The advisor helped me to polish the grammar and made the sentences neater.

I forget to say one thing, I have another adviser. Let's say A2. The one I'm having dispute with is A1. A1's most significant  contribution is writing the paper. A2 helps me with the "big picture". Because A2 is more junior than A1, A2 only becomes co-author. 

Also thanks for everyone who wrote answers and comments. All of you gave me a lot of new perspectives.
You write:


  The only "effort" my adviser does is writing the actual paper


Well, in many fields, that would make them sole author. It certainly gives them a very strong claim to be first author, in fields where authorship is determined by contribution to the paper.

If you want to be first author, then write the paper yourself.

And if you can't, then don't expect first authorship, and be grateful for co-authorship (rather than an acknowledgement).

You've now added that you have done a bit of the writing, but your adviser has done most of it. So yes, they would, in many fields, still get first authorship, and you would get a co-authorship on that basis, assuming what you've written is a non-trivial proportion of the whole.