Coakley was elected Massachusetts Attorney General in the 2006 general election as a Democrat, defeating Republican Larry Frisoli with 73% of the vote. She was sworn in on January 17, 2007. Coakley is the first woman to serve as Attorney General in Massachusetts.
On July 8, 2009, she filed a law suit, challenging the constitutionality of the Defense of Marriage Act. The law suit claimed that Congress "overstepped its authority, undermined states' efforts to recognize marriages between same-sex couples." Massachusetts is the first state to challenge the legislation.
In 2009, Coakley won settlements of $60 million from Goldman Sachs and $10 million from Fremont Investment & Loan for their abuse of subprime loans and lending.