What a joke!

A teen firebug smiled for the cameras as he was walked from a Brooklyn precinct on Monday — hours after telling cops he set the fire that nearly killed two officers because he was “bored.”

“I decided to take a lighter and light the top of the mattress because I was bored,” Marcell Dockery, 16, told cops, according to a law enforcement source.

“I saw the mattress catch fire and I tried to blow out the flames. I thought the flame was out and I looked back and the mattress was in flames. I started knocking on apartment doors to alert people to the fire.”

Dockery — who set up an entire Facebook page devoted to his “obsession’’ with fire — was charged with felony arson and assault and reckless endangerment.

“He is really obsessed with this arson thing,’’ a source said. “He’s a firebug. He was bragging about it on his Facebook page.’’

He said nothing but smirked for reporters as he was led from the 60th Precinct for his criminal court arraignment.

Dockery was previously busted in 2010 on a sealed arson rap, and admitted to cops he had a “problem” with starting blazes.

He also has sealed arrests for criminal mischief and pot possession from earlier this year.

The suspect — a 12th-floor resident of the building — was spotted on surveillance video leaving after setting the fire.

Mayor de Blasio, who along with Police Commissioner Bill Bratton visited critically wounded Officers Dennis Guerra, 38, and Rosa Rodriguez, 36, in the hospital, said Monday, “At this moment, we have two officers fighting for their lives. They are in critical but stable condition.’’

The two cops were choking and blinded by smoke as they came out of an elevator on the 13th floor, where Dockery allegedly set the mattress ablaze. The police partners frantically radioed for help.

Raw audio: Police radio transmissions from the scene

“Help! Help!” Rodriguez can be heard screaming over the police radio.

She and her partner can be heard yelling, “Eighty-five! Eighty-five!’’ a police distress code as they struggled to give their location to a dispatcher.

At first, Rodriguez said they were on the 14th floor, but Guerra quickly corrected her and said the 13th.

“Can’t breathe! Can’t breathe! Can’t see!” Guerra’s gasps in desperation, right before firefighters found the partners unconscious.

Guerra, a married dad of four, was in cardiac arrest by the time help arrived.

He was rushed to Coney Island Hospital and then airlifted to Jacobi Hospital in The Bronx before being finally transported to Montefiore Medical Center as doctors struggled to stabilize him.

Rodriguez, a mother of four, was transported from Lutheran Hospital in Brooklyn to Cornell Medical Center’s burn unit in Manhattan and placed in a hyperbaric chamber.

The partners were on routine patrol at the housing project when they went to investigate the 911 call of smoke from a fire on the 13th floor, officials said.

City Councilam Rory Lancman (D-Queens) wrote a letter to Bratton on Monday calling for better training of cops in the event of fire.

Elevators are taboo to take during a suspected blaze, given they can trap you in flames and smoke or halt between floors.

“It’s a problem first responders face regardless of whether they’re trained as firefighters or police officers,’’ a source said of knowing the rules.

At the suspect’s building, one neighbor called him “a quiet kid.

“The family has been here for years. Sometimes you run around with the wrong crowd,’’ said Elly Torres, 38, who lives on the 13th floor.

“I prayed for the officers before I went to bed,’’ she said.

A tenant-association leader, Wanda Feliciano, said it wasn’t the first time a firebug had struck there.

“We had two fires in this building, it happened before,’’ she asid.

The cops walked into “a death trap’’ by taking the elevator, said resident Robert Maldonado, 50. “I feel bad for [them].’’

Louise Harrington, a 70-year-old resident from the 14th floor, added, “It hurts that two police officers come here to save our lives and they are the ones getting hurt.”

“I pray they recover. I’m quite sure they didn’t know this would happen to them.”

Additional reporting by Kate Sheehy, Larry Celona, Lorena Mongelli and Kevin Sheehan