Why do editors sometimes accept a paper even if a reviewer recommends rejection? For the last many days, I have a question in mind related with the editorial decision of accepting or rejecting the manuscript after peer-review:

Few days back I got a review report from a very reputed mathematics journal in which reviewer 1 had given some good points and suggestions to further improve the paper while reviewer 2 had given some points and rejected my manuscript. 
Although, its not tough to revise the paper as per the suggestions of reviewer 2.
I would like to know why editor has given me chance to revise the manuscript while reviewer 2 has rejected it. I asked this question because in the past I had bad experience of rejection despite of getting acceptance from one of the reviewers.
It is up to the editor whether to accept or reject. The reviewers only make recommendations.  Even if the reviewers give positive recommendations, the editor can decide to reject a paper. 

If both reviewers give negative recommendations, it is much less likely for the editor to accept a paper. If there is a mix of opinions the editor  has to make a judgment, subject to whatever internal procedures the journal has in place. It seems like, this time, the decision was favorable for you.