Rapper Ja Rule will head to prison for two years next year, after pleading guilty to three-year-old gun charges this morning.

The hip hop star presented a brave front to fans — cheerfully posing and signing autographs — as he left Manhattan Criminal Court after pleading to attempted criminal possession of a weapon, but was clearly unhappy with the looming sentence.

He remains free pending his next court date, Feb. 9, when a judge is expected to fix a date for him to turn himself in.

“Today is not a good day for me. I’m not in the mood,” he told reporters. “It’s not a good day, fellas.”

Ja Rule had been busted in 2007, when cops searched his Maybach as he left a concert at the Upper West Side’s Beacon Theatre, seizing a .40-cal unlicensed handgun found inside.

In today’s plea, Ja Rule admitted that he had “dominion and control” over the gun.

“He admits that the gun was in the vehicle owned by his company, and that therefore it was in a vehicle under his control,” said his lawyer, Stacey Richman.

Complicating matters was the microscopic amount of the rapper’s DNA was swabbed off the gun, according to Assistant district attorney Joan Illuzzi-Orbon — making it a difficult possession case to take before a jury.

Had Ja Rule gone to trial and been convicted of the top charge against him, outright criminal possession, he faced a mandatory minimum of 3 and 1/2 years prison.

Richman had argued that the DNA sample was too small to reliably test — and that the several cells swabbed off the gun could have been transferred there indirectly, without Ja Rule having actually handled the gun.

But Manhattan Supreme Court Justice Richard Carruthers denied defense motions to challenge the science behind the gathering and processing of the DNA.

This morning, the same judge warned the rapper against getting into further trouble pending sentencing.

“Because of your guilty plea here today, you’ll have a record of having committed a violent felony,” the judge said. “This is is a very serious matter.”