In short: The Doctor became 407th Lord President of Gallifrey in The Invasion of Time, but most likely lost the presidency at the end of that storyline - he apparently forgot, and so was succeeded by Chancellor Borusa. However, he is again President later, losing the office some unspecified time before The Trial of a Time Lord. He might have been President a third time, but no details are known about that (yet).
In The Deadly Assassin, the (4th) Doctor is one of two candidates:
GOTH: You're keeping a close watch on the Doctor, I hope?
SPANDRELL: Someone is with him all the time.
GOTH: Good. You know that, apart from myself, he is the only other candidate in this election?
SPANDRELL: Is that so.
This is followed by the events of The Invasion of Time, where the (4th) Doctor takes office:
DOCTOR: I am here to claim my legal right.
DOCTOR: I claim the inheritance of Rassilon. I claim the titles, honour, duty and obedience of all colleges. I claim the Presidency of the Council of Time Lords.
DOCTOR: You don't dispute my claim, then?
BORUSA: No, only the arrogance with which you present it.
BORUSA: I'll do what I can to persuade the Cardinals to accept you as their President.
DOCTOR: I am the President! No persuasion is necessary.
BORUSA: Politeness dictates
DOCTOR: I am the President! Is there another candidate legally?
BORUSA: No. That was an unfortunate oversight.
However, by the end of this story, the Doctor has (seemingly) forgotten about this:
BORUSA: Your Excellence.
DOCTOR: Excellence? Excellence?
DOCTOR: Is this some kind of a joke, Borusa? It's not like you to make jokes.
BORUSA: Have you forgotten your induction?
DOCTOR: My induction?
BORUSA: The Vardans?
DOCTOR: (sotto) Vardans.
BORUSA: The Sontarans?
DOCTOR: (sotto) Sontarans.
BORUSA: Doctor, you saved Gallifrey.
DOCTOR: I have? Oh. Well, what do you think of that, Leela?
LEELA: I think you've gone mad.
BORUSA: He remembers nothing of it. It is the wisdom of Rassilon.
That episode was the end of a season (the final Leela episode), and either he lost the office between then and the next episode, or the writers also forgot. When we (and the 4th Doctor) are introduced to Romana in The Ribos Operation, she says:
ROMANA: My name is Romanadvoratnelundar.
DOCTOR: I'm so sorry about that. Is there anything we can do?
ROMANA: The President of the Supreme Council sent me.
Presumably the "Supreme" Council is the same High Council. The Doctor does say:
DOCTOR: That information is confidential! That President. I should have thrown him to the Sontarans when I had the chance.
I could certainly believe that this is an tongue-in-cheek reference to the himself, so it could be that the Doctor as President sent Romana to himself, except, that in The Stones of Blood (briefly mentioned in The Armageddon Factor as well) we find out that:
DOCTOR: Romana, you were not sent on this mission by the President of the Supreme Council.
DOCTOR: No, no, you weren't.
ROMANA: But, I saw. He told me. ... Well, what am I doing here?
DOCTOR: The voice you just heard and the being you saw in the shape of the President was the White Guardian, or to be more accurate, the Guardian of Light and Time as opposed to the Guardian of Darkness, sometimes called the Black Guardian. They can assume any shape or form they wish.
By the time of Arc of Infinity, Borusa is the 408th President:
BORUSA: You too have regenerated.
DOCTOR: Indeed, President Borusa.
In The Five Doctors, Borusa loses the presidency, and the (5th) Doctor is returned to office as the 409th President:
FLAVIA: You are safe, Doctor. I feared President Borusa had... Where is President Borusa?
DOCTOR: Unavailable. It seems the legend about Rassilon is true.
FLAVIA: You must make a full statement to the High Council.
DOCTOR: Oh, must I?
FLAVIA: It can form part of your inaugural address.
DOCTOR: My what?
FLAVIA: Doctor, you have evaded your responsibilities for far too long. The disqualification of President Borusa leaves a gap at the very summit of the Time Lord hierarchy. There is only one who can take this place. Yet again, it is my duty and my pleasure to inform you that the full Council has exercised its emergency powers to appoint you to the position of President, to take office immediately.
DOCTOR: Oh, no.
FLAVIA: This is a summons no Time Lord dare refuse. To disobey the will of the High Council will attract the severest penalties.
DOCTOR: Very well, Chancellor Flavia. You will return to Gallifrey immediately and summon the High Council. You have full deputy powers until I return. I shall travel in my Tardis.
FLAVIA: Oh, but Doctor -
DOCTOR: You will address me by my proper title. I am President, am I not? You will obey my commands. (To Tegan and Turlough) Into the Tardis. (To the guards) You will escort Chancellor Flavia back to her duties.
At some point after that, he is deposed. He (and we) find this out in The Trial of a Time Lord:
DOCTOR: I am Lord President of Gallifrey. You can't put me on trial.
INQUISITOR: Doctor, since you willfully neglected the responsibility of your great office, you were deposed.
DOCTOR: Oh. Is that legal?
In the 4th part of this storyline, generally known as The Ultimate Foe, the (6th) Doctor is asked to stand again, but declines:
INQUISITOR: Now then, once law and order have been restored, a new High Council will need to be elected. Can I persuade you to stand for Lord President again?
DOCTOR: Ah. Ah ha. I've a better idea.
MEL: He's going to suggest you stand.
DOCTOR: Indeed I am. And were there such a thing as an intergalactic postal vote, you'd have mine.
Later, the 7th Doctor calls himself "President-Elect" in Remembrance of the Daleks:
DOCTOR: Ah, there you are. This is the Doctor, President Elect of the High Council of Time Lords, Keeper of the legacy of Rassilon, Defender of the Laws of Time, Protector of Gallifrey. I call upon you to surrender the Hand of Omega and return to your customary time and place.
EMPEROR: Ah, Doctor. You have changed again. Your appearance is as inconstant as your intelligence. You have confounded me for the last time!
So it's possible that he was President a third time (or possible he was stretching the truth a little, or that in the Dalek's timeline he was still President-Elect, but not in his, or that he was just using the titles the Emperor would be familiar with, since he had regenerated since their last encounter).