More than a thousand police officers, relatives and friends gave an emotional and spirited farewell yesterday to a beloved school safety officer who died after being punched, allegedly by a 12-year-old girl.

Mayor Michael Bloomberg was among those to honor Vivian Samuels-Benjamin, 58, at her local Wayside Baptist Church in Bedford-Stuyvesant, where the devout woman was a volunteer usher.

“Going to school isn’t something that all kids look forward to,” Bloomberg said before Samuels-Benjamin’s golden coffin as her family members tearfully embraced.

“But at least the kids at the Maggie Walker Middle School had it a bit easier than a lot of other schools, because every day . . . there was Vivian Samuels-Benjamin with a few words of wisdom or an early pick-me-up.”

The funeral drew more than 1,500 police and school safety officers, many of whom could be seen wiping away tears.

The lifelong Brooklynite was remembered as a dedicated church member and loving mother of two boys and a deceased daughter. Her hearty sense of humor and generous spirit were also recounted, as was her habit of bringing fellow officers a sandwich and a slice of pie.

“It wasn’t always easy,” said Police Commissioner Ray Kelly.

“In her career safeguarding public schools, Vivian made several arrests, but more than anything, she made a great many friends.”

In fact, colleagues said, it was because of Samuels-Benjamin’s rapport with the students that she was called last Friday to handle the unruly 12-year-old, who allegedly punched the officer twice, causing an apparent heart attack.

The girl has been charged with harassment, but is expected to face more serious charges.

When she wasn’t helping kids work through problems – with her signature phrase, “Get your life right” – Samuels-Benjamin was listening to gospel music.

As her son gave the eulogy, the church erupted into gospel singing, clapping and even dancing.

“I did my crying, and I might cry a little more, but right now I want to feel the praise,” said the son, Pastor Irving Benjamin Jr., as friends and relatives stood to cheers of “Praise to God.”