Gonzalez entered politics when he ran for San Francisco District Attorney in 1999. He campaigned to halt political corruption and marijuana prosecutions.[5] Gonzalez lost to incumbent Terence Hallinan. In a field of five candidates, he finished third with 20,153 votes (11 percent of the total).[6]

In 2000, a system of electing supervisors by district rather than citywide took effect. At the urging of Supervisor Tom Ammiano, Gonzalez moved from his home in the Mission District to run for supervisor in newly made District 5.[7] In early November, shortly before the run-off election, Gonzalez switched party affiliations from the Democratic Party to the nascent Green Party.[8] His opponent, Juanita Owens, tried to capitalize on many Democrats' ill feelings toward the Green Party in the wake of Ralph Nader's involvement in the acrimonious 2000 presidential election,[9] but Gonzalez won the run-off election. He was part of a slate of candidates who wanted to change the direction of city policy, in opposition to the "Brownmachine," a Democratic Party political machine that had dominated local politics for over 30 years behind Mayor Willie Brown, the Pelosi family, and other Democrats.[10] His supporters saw his election as a turning point in local politics.[11][12]

Gonzalez's critics considered him a stubborn and willful ideologue. When the Board put forth a resolution commending San Franciscan Congresswoman Nancy Pelosi for being elected House Minority Whip and being the first woman to hold that position, Gonzalez was the only board member who voted against it. Gonzalez said that supervisors should not issue commendations for winning partisan political positions and that he had written a personal note to Pelosi congratulating her, as she had done him for being elected board president.[13][14] Gonzalez refused to meet with Brown during his first two years on the Board of Supervisors, saying he did so to avoid being subject to Brown's influence rather than as a matter of disrespect.[15] Two sources reported that Gonzalez defied Brown by walking out of the mayor's State of the City address in 2002.[16][17] However, Gonzalez later told SF Weekly that he was never in attendance.[18]

In January 2003, Gonzalez was elected president of the Board of Supervisors after seven rounds of voting, most of which had Gonzalez vying for a majority vote with supervisors Aaron Peskin and Sophie Maxwell. When Peskin dropped out Gonzalez emerged the winner, counting among his supporters conservative Board member Tony Hall, who said when asked why he voted for Gonzalez, "Gonzalez is a man of integrity and intelligence who will carry out his responsibilities fairly and impartially."[19][20][21]

Gonzalez hosted monthly art exhibits in his City Hall office. At the last reception, graffiti artist Barry McGee spray-painted "Smash the State" on the walls of the office as part of his exhibit."[22] Gonzalez told the press that he knew his office would be repainted for the next occupant.

In August 2003, Gonzalez ran for Mayor of San Francisco in a bid to replace outgoing two-term mayor Willie Brown.[23] On a ballot with nine candidates, Gonzalez finished second in the primary election on November 4 behind Gavin Newsom, a Democrat and fellow member of the Board of Supervisors who had been endorsed by Brown. Gonzalez received 19.6 percent of the total vote to Newsom's 41.9 percent.[24] Because none of the candidates received a majority, a run-off election was held on December 9.

Gonzalez faced a difficult run-off election; only 3 percent of voters in San Francisco were registered to his Green Party the party to which he belonged.[25] Although Gonzalez was endorsed by several key local Democrats, including five members of the Board of Supervisors, national Democratic figures, concerned about Ralph Nader's role in the 2000 presidential election, campaigned on Newsom's behalf.[26][27]Bill Clinton, Al Gore, Jesse Jackson, Dianne Feinstein, and Nancy Pelosi all campaigned for Newsom. Gonzalez said about his candidacy, "They're scared, not of a Green being elected mayor, but of an honest person being elected mayor."[28]

Newsom won the runoff race by a margin of 11,000 votes, capturing 53 percent of the vote to Gonzalez's 47 percent[29]

Following the mayoral contest, Gonzalez announced he would not seek re-election to the Board of Supervisors. Explaining his decision to retire from politics, he said:

I like the whole idea of disengaging from politics for a while and looking at things from the outside. I think the world would be a better place if politicians returned to private life from time to time... Hey, you've got to follow your instincts, you know. That's how I got into politics in the first place, joined the Green Party, ran for the board presidency and later for mayor. What am I supposed to do now? Not listen to myself?"[30]

In January 2008, Gonzalez, along with several other prominent Green Party members, launched Ralph Nader's 2008 Presidential Exploratory Committee to support a possible Nader candidacy.[35] On February 28, 2008, only four days after announcing his presidential bid, Nader named Gonzalez as his running mate for the 2008 presidential election.[36]

In 2008, Gonzalez left the Green Party and changed his registration to decline to state. "I expressly said to Nader that I would not run with him if he sought the Green Party nomination," Gonzalez said. "The question after the campaign was: is there a reason to go back to the Green Party?" Among the reasons he cited for the party's slide were infighting, inadequate party-building work, and the party's failure to effectively counter criticisms of Nader's 2000 and 2004 presidential campaigns. "We were losing the public relations campaign of explaining what the hell happened," he said.[37]

Nader announced that he and Gonzalez would not seek the Green Party nomination but would run as independents. On March 4, 2008, Gonzalez announced that he had left the Green Party and had changed his voter registration to independent.[38] The change, he said, was to accommodate states, including Delaware, Idaho and Oregon, that do not allow members of political parties to run as independents.

On October 18, 2008 Gonzalez and Nader also held a large protest on Wall Street following the passage of the government bailout bill.[39] Their opposition to the bailout was a key issue of the Nader/Gonzalez campaign, in contrast to the Democratic and Republican Party candidates who supported the bill.

Gonzalez participated in the third party vice-presidential debates, along with Constitution Party vice-presidential candidate Darrell Castle and LibertarianWayne Allyn Root, held in Las Vegas, on November 2, 2008.[40] The event was hosted by Free and Equal.org and Free & Equal Elections (FREE), an organization of political parties, independent citizens and civic organizations formed to promote free and equal elections in the United States.[40]

In San Francisco, Gonzalez received fewer votes citywide when he ran for vice president in 2008 (3,682)[41] than he received in District 5 (12,743)[42] when he ran for supervisor in 2000. Will Harper, editor of the SF Weekly, wrote:

"Eight years ago, 24,819 San Franciscans voted for Nader, according to Department of Election records. Of course, we've all had eight years to realize that throwing away our vote on a third-party candidate can do a lot of damage, so Nader's poor showing this time was not entirely unexpected. But Nader supposedly had one thing going for him in San Francisco that other candidates did not: A running mate from the city, former supervisor and Green Party pinup boy Matt Gonzalez. Obviously, having a hometown guy in the race didn't make a difference for S.F. voters sick of Republican rule of the White House".[42]