Even before the sun rose, officers donned their finest and made their way to the church in Prince George’s County. Arriving in cruisers with flashing lights, on rumbling motorcycles and on horseback, thousands of them stretched beneath the towering steeple to wait.

And when the flag-covered casket carrying the young detective arrived, the expanse of white-gloved officers uniformed in blue and gray and brown snapped to solemn attention.

Nearly two weeks after the death of Prince George’s police officer Jacai Colson, law enforcement members, elected officials and ordinary citizens descended on the First Baptist Church of Glenarden on Friday to pay their respects to a man they say sacrificed his life to protect his community and colleagues.

“He loved his job and the people he swore to protect,” said Prince George’s County Executive Rushern L. Baker III. “It was that unintentional valor that allowed him to stand in the face of danger and not blink or waver.”

Colson, 28, was killed in a March 13 shooting started by a man who police say plotted and carried out an ambush on officers outside a police station while his two younger brothers recorded it on video. Colson, an undercover narcotics detective who was off duty and wasn’t in uniform when he arrived at the scene, was fatally wounded by another officer responding to the shooting.

Three Prince George's County brothers are being held in connection with the fatal shooting of Officer Jacai Colson in Landover March 13. Police said that Colson was killed by another officer who perceived him as a suspect. (Victoria Walker/The Washington Post)

Both laughter and anguish punctuated the two-hour ceremony, with officers from Chicago, the local Washington region and the East Coast filling the 4,000-seat sanctuary.

Capt. Stanley Johnson, acting chief of the Maryland-National Capital Park Police in Prince George’s, said he understood why officers from across the country attended.

“It is the badge, it is the uniform,” Johnson said. “We are all one family. When one officer suffers, we all suffer.”

Colson is the 29th officer in Prince George’s to die in the line of duty. He would have celebrated his 29th birthday last week.

As Colson’s mother, father and brother approached his open casket to say one more goodbye, his mother threw back her head and sobbed. And as the lid closed, she stretched her arms toward her son and wept before someone stretched an American flag over the pewter-colored casket.

Maryland Gov. Larry Hogan (R), one of several elected officials who attended the service, lamented that this was the third time in recent weeks the region has had to gather for the funeral of an officer who died in the line of duty. Law enforcement officers in Virginia’s Prince William County and Maryland’s Harford County were killed recently in shootings.

The funeral for Prince George’s County officer Jacai Colson was attended by thousands Friday, as people came to pay their respects to an officer killed in the line of duty. Colson was shot and killed by friendly fire while responding to an attack on a police station in Landover March 13. (Hamil Harris/The Washington Post)

Like others, Hogan praised Colson’s bravery in defending the community against an active shooter.

“His spirit is the same spirit of compassion that guides each and everyone in uniform,” Hogan said. “He will forever be remembered as a true hero.”

Prince George’s Police Chief Henry P. Stawinski III has said that Colson drew fire toward himself the day of the gun battle, allowing other officers time to take position and stop the gunman.

Stawinski said it is love that leads officers like Colson into peril and it is that love that could lead to their ends. But he concluded his remarks on a hopeful note.

“Today we weep, but we do not give up,” Stawinski said. “Today we hope. Today we rise anew.”

Michael Ford, 22, has been charged with second-degree murder and more than 20 other counts in connection with the case. Police say he recorded his last will and testament before launching the gunfight with officers. Two of Ford’s younger brothers — Malik Ford, 21, and Elijah Ford, 18 — have also been charged. All three are from Prince George’s.

John Teletchea, president of the county’s police union, called the day Colson died “one of the darkest days in the county.” The shooting at the police station was an “attack on our society and our way of life,” he added.

He urged the crowd to “reject divisive rhetoric” that may have emerged from Colson’s death.

A friend of Colson’s from high school echoed the sentiment.

“It is not all one style of lives matter,” Desai Langley said. “All lives matter.”

As the church filled, photos of Colson’s life flashed on large screens above a stage — images of him in Little League, a happy child at the beach, at graduation. A native of the Philadelphia area, Colson graduated from ­Randolph-Macon College in Virginia before following his grandfather’s footsteps and becoming a police officer.

Colson, who had been with the Prince George’s police department for four years, has been remembered as a dedicated detective who dreamed of working for the FBI or the Drug Enforcement Administration.

On Friday, friends shared their favorite memories of Colson, chuckling as they recalled the jovial buddy who would sing around the house in boxers and dingy slippers or battle them in dance parties and cook-offs.

Colson’s family, wearing matching gray suits, later addressed the crowd. They recalled a loving son and brother and avid Philadelphia Eagles fan who they said they also will now be remembered as a hero.

Colson’s mother, Sheila Colson, stood strong behind the lectern, telling the audience how her son, born three months early, had a difficult start in life.

“He fought to get here,” his mother said, “and he fought going out.”

The service ended with the strain of bagpipes playing “Going Home” and “Amazing Grace.” Arm-in-arm and holding hands, the slain officer’s brother, mother and father followed the casket out of the church and to the hearse.

As friends, family and police officers poured from the sanctuary to comfort Colson’s mother, she offered comfort in return.

“It is going to be okay,” she told them, her face wet with tears. “It was just his time.”

Justin Jouvenal contributed to this report.