Gogarty joined the Green Party in 1989 as a student. He ran unsuccessfully in the 1991 local elections for Fingal County Council. He was first elected at the 1999 local elections for the Lucan local electoral area of South Dublin County Council.
Gogarty previously contested the 1992 and 1997 general elections in the Dublin West constituency. He also ran at the 1996 by-election caused by the death of Brian Lenihan, Snr. At the 2002 general election he was elected to the Dáil for the new Dublin Mid-West constituency. He was the first Green Party member to be elected in a three-seat constituency. After his election, Gogarty gave up his local council seat, in line with Green Party policy against dual-mandate and was succeeded by the late Fintan McCarthy. At the 2007 general election, he retained his Dáil seat, taking the second seat in the enlarged constituency.
Following the Green Party's entry to government in 2007, Gogarty was appointed chairman of the Oireachtas Committee on Education and Science.
In 2002, 2003 and again in 2008, Gogarty called for the pay of members of the Irish Parliament and Seanad to be cut. In November 2003 he described the decision to raise TDs pay by 13% during the Celtic Tiger era, compared with 6% for pensioners and social welfare recipients as a "urination" on the less well off in society.
On 3 August 2010, Gogarty wrote to the Clerk of the Seanad asking that newspaper claims alleging that Senator Ivor Callely had supplied phone expenses claims on headed paper belonging to a company which no longer existed be investigated. Gogarty appeared on the RTÉ Joe Duffy radio show discussing this issue. He went to Lucan Garda station the next day and requested an investigation.
In November 2010, he brought his 18-month-old daughter to a Green Party press conference. The following day, many callers to a radio show criticised his decision. He responded that his regular child minder was not available when the press conference was called.
Gogarty's work in protecting educational investment during a period of cutbacks has been widely reported in the media, including a profile in The Irish Times in November 2010, which claimed that his contribution was recognised by admirers and detractors alike.
On 11 December 2009, during his contribution to a debate in the Dáil on the Social Welfare bill of the 2010 budget, Gogarty said to Labour Party TD Emmet Stagg: "With all due respect, in the most unparliamentary language, fuck you Deputy Stagg! Fuck you!" He immediately apologised to the House for his use of unparliamentary language, which was criticised by Deputy Lucinda Creighton, who demanded his suspension. The incident was referred to a sitting of the Dáil committee on procedure and privileges, when it emerged that "fuck" is not included among the list of forbidden words set out in the Salient Rulings of the Chair, the document which regulates the behaviour and conduct of TDs. Gogarty later clarified that the outburst was totally unintentional and not premeditated as some had suggested. He also said that the outburst had to be taken in the context of his contribution during the debate that day as well as a very turbulent and heated debate the previous night.
Gogarty lost his seat at the 2011 general election, polling 3.47% of the poll and losing his right to reclaim election expenses.
Gogarty withdrew from politics until 2014 after losing his Dáil seat, and let his membership of the Green Party lapse. In early 2014 he decided to run for South Dublin County Council in local elections that June. He considered returning to the Green Party but ultimately ran a "low key campaign" as an independent. He was elected on the 12th count to the fourth of eight seats in the Lucan local electoral area.
In September 2015 Gogarty announced his intention to contest the 2016 general election as part of the Independent Alliance in the Dublin Mid-West constituency. He failed to be elected, receiving 5.9% of the 1st preference votes.
In June 2011 he spent four days filming at the "Charity ICA Bootcamp" in County Louth. The show was broadcast on RTÉ the following August. He raised €5,000 for Pieta House, a suicide prevention and awareness charity. From July to November 2011 Gogarty was involved in season 4 of the RTÉ television series Celebrity Bainisteoir managing Oughterard's Seamus Ó Máille GAA Club, Galway. He was beaten by Tony Cascarino's team.
In August 2012, he released his debut single "Wishing on a Photograph" under the stage name of His Sweet Surprise. His third single "Know You All My Life" reached number one on the 7Digital Download Chart in January 2013. He released a music album on 17 February 2013.