He began his career in the Hampden District Attorney's Office as an Assistant District Attorney in 1990. From 1995 to 2011, he worked as an attorney in private practice as a sole practitioner, focusing his practice on criminal defense matters in State and Federal court. He then became District Attorney for Hampden County, Massachusetts, serving as the chief law enforcement officer of the county and managing an office of nearly 140 employees. Under Mastroianni, the D.A.'s Office opened an unsolved-crime unit and a DNA unit, allowing several cold cases to be solved.
Federal judicial service
When a vacancy on the U.S. District Court for the District of Massachusetts opened, Mastroianni interviewed for the position before a committee to screen and recommend possible candidates, convened by Senator Elizabeth Warren and led by former District Judge Nancy Gertner. Mastroianni submitted his application in early 2013, went through several rounds of interviews, and received the recommendation. On September 24, 2013, President Barack Obama nominated Mastroianni to serve on the court, to the seat vacated by Judge Michael Ponsor, who took senior status on August 15, 2011. Mastroianni was rated "well qualified" for the post by a substantial majority of the American Bar Association's Standing Committee on the Federal Judiciary. He received a hearing before the Senate Judiciary Committee on February 11, 2014. His nomination was reported out of committee by voice vote on March 6, 2014. On May 22, 2014 Senate Majority LeaderHarry Reid filed for cloture on the nomination. On June 3, 2014, the Senate voted 56–39 on the motion to invoke cloture. On June 4, 2014, the Senate voted to confirm Mastroianni on a 92–2 vote. He received his judicial commission the following day, and was ceremonially sworn in on August 1, 2014.
Notable cases
Mastroianni presided over a trademark case involving the name "fire cider". After a Pittsfield, Massachusetts-based company registered the phrase as a trademark in 2012, others brought suit, contending that the phrase is a longstanding phrase in herbalism that cannot be trademarked. In 2019, Mastroianni issued a decision siding with the challengers and holding that "fire cider" is a generic term. In 2017, Mastroianni dismissed a defamation lawsuit brought by Katherine Mae McKee against comedian Bill Cosby. After McKee accused Cosby of raping her in 1974, a Cosby representative published a public letter in 2014 questioning her credibility, prompting the woman to sue for defamation. In dismissing McKee's suit, Mastroianni held that the Free Speech Clause of the First Amendment to the United States Constitution gave broad liberty to for individuals publicly accused of misconduct to defend themselves without fear of being held liable for defamation.