The 58-year-old actor, who for two decades portrayed psychiatrist Dr. Frasier Crane on the hit NBC sitcoms "Cheers" and "Frasier," most recently starred in the Starz cable channel drama series "Boss" as a fictional Chicago Mayor Tom Kane, in the mold of Richard J. Daley.
Grammer's role in the "Transformers" science-fiction action film sequel was first reported by Deadline Hollywood. It identified his role as "a counterintelligence guy" named Harold Attinger.
The unnamed sequel, to be released June 27, 2014, also stars Irish actor Jack Reynor, U.S. actress Nicola Peltz and U.S. actor Stanley Tucci.
Peter Cullen, who voiced Optimus Prime in the earlier films, will reprise his role as the leader of the Autobots.
Production starts in July.
The film, written by Ehren Kruger, "takes place exactly four years after the war in Chicago," director Michael Bay says on his website. "The story makes a very natural transition, and reason as to why we have a whole new cast.
"This 'Transformers' will feel very different than the last three," Bay writes. "We are embarking on a new trilogy."