The Police Department in Yarmouth, Mass., was mourning the death of one of its officers, Sean Gannon, last month when a bouquet of flowers arrived at the station bearing a card with five unexpected words: “From the New York Yankees.”

Officer Gannon was shot and killed while serving a warrant in neighboring Marstons Mills, a tiny village in Cape Cod, where the Yankees are considered bitter rivals.

“I’m a die-hard Red Sox fan, and my first reaction was, ‘Call the delivery guy and tell him to take them back,’” said Frank Frederickson, the Yarmouth police chief. “I say that in jest, of course. That is a class move, and it meant a lot to us. All the guys came down and wanted to see it. They were like, ‘Are you kidding me?’”

Reactions were similar at the sheriff’s department in Lebanon, Ind., last month and at a home in Fargo, N.D., in 2016, and dozens of other locations from Maine to Alaska. For the past three years, the Yankees have been quietly sending flowers to the families and police departments of slain law enforcement officers across the country.