Funnyman Will Ferrell — famous for a “Saturday Night Live” skit in which he plays a cowbell-obsessed musician — rushed to the aid of one of the band’s pipers when he was hit by a tree branch in Brooklyn’s Green-Wood Cemetery.

Ferrell, who was taping a funeral scene with the band for “The Other Guys” — a comedy about washed-up cops taking a shot at redemption — provided one of the injured cops, retired Detective Daniel Sprague, with a little laughter while medics made their way to the scene.

“That’s gotta hurt!” Ferrell told the cop.

Sprague, who was hit in the head by the limb, said the comedian’s jokes helped calm him down.

Co-stars Mark Wahlberg and Michael Keaton also ran to the cop’s side.

“They were very nice,” Sprague said of the Hollywood heroes.

“They showed a lot of concern. They were grateful for the job we do every day.”

The 18-year-veteran from Long Island was taken to Lutheran Medical Center, where he received four stitches.

The band and the actors were among 30 people in the cemetery at around noon when the branch broke off.