He wasn't *just* Mayor of SF, he was a major player statewide and extremely powerful. He mentored Gavin Newsom as well, and continued to be a king maker after he retired from political office. He appointed his girlfriend Kamala Harris to various high profile commissions where she could meet the right people, and that propelled her up the ladder starting with him walking her into her DA position.
This is how it works in most one party jurisdictions - all of the power rests with party leaders, since the November election is a foregone conclusion.
People who gain power in the party do so with political patrons, who maneuver their favored person into power, usually in exchange for favors they will use elsewhere, to keep political power. This is a model of politics that goes back centuries. Ancient Rome had such structures, although it extended to all manner of society - "patrones" who directed the lives of those who served them.
This is mostly how Obama gained power. Bear in mind, that until he became a State Senator - he was politically nobody. He caught the eye of Alice Palmer, who promised him her seat once she decided to resign. When it came time to resign, she changed her mind and Obama immediately challenged the petitions of his opponents and found they were ALL fraudulent. He got the nomination unopposed, and continued on as Illinois state senator for three terms until his run for the U.S. Senate.
He was elected Senator in one of the dirtiest campaigns I've ever seen, but I can't believe to this day they ran that buffoon Alan Keyes against him. I always wondered if Jack Ryan ever had a chance.
TWO years into his seat as Senator, he began to run for President. He got everyone's attention with his DNC speech in 2004.
Seriously - he went from State Senator in 2004 to President in 2008. Who gets that far, without help?