When former President Barack Obama said he was “heartened” by anti-Trump protests, he was sending a message of approval to his troops. Troops? Yes, Obama has an army of agitators — numbering more than 30,000 — who will fight his Republican successor at every turn of his historic presidency. And Obama will command them from a bunker less than two miles from the White House.

In what’s shaping up to be a highly unusual post-presidency, Obama isn’t just staying behind in Washington. He’s working behind the scenes to set up what will effectively be a shadow government to not only protect his threatened legacy, but to sabotage the incoming administration and its popular “America First” agenda.

He’s doing it through a network of leftist nonprofits led by Organizing for Action. Normally you’d expect an organization set up to support a politician and his agenda to close up shop after that candidate leaves office, but not Obama’s OFA. Rather, it’s gearing up for battle, with a growing war chest and more than 250 offices across the country.

Since Donald Trump’s election, this little-known but well-funded protesting arm has beefed up staff and ramped up recruitment of young liberal activists, declaring on its website, “We’re not backing down.” Determined to salvage Obama’s legacy, it’s drawing battle lines on immigration, ObamaCare, race relations and climate change.

Obama is intimately involved in OFA operations and even tweets from the group’s account. In fact, he gave marching orders to OFA foot soldiers following Trump’s upset victory.

“It is fine for everybody to feel stressed, sad, discouraged,” he said in a conference call from the White House. “But get over it.” He demanded they “move forward to protect what we’ve accomplished.”

“Now is the time for some organizing,” he said. “So don’t mope.”

Far from sulking, OFA activists helped organize anti-Trump marches across US cities, some of which turned into riots. After Trump issued a temporary ban on immigration from seven terror-prone Muslim nations, the demonstrators jammed airports, chanting: “No ban, no wall, sanctuary for all!”

Run by old Obama aides and campaign workers, federal tax records show “nonpartisan” OFA marshals 32,525 volunteers nationwide. Registered as a 501(c)(4), it doesn’t have to disclose its donors, but they’ve been generous. OFA has raised more than $40 million in contributions and grants since evolving from Obama’s campaign organization Obama for America in 2013.

OFA, in IRS filings, says it trains young activists to develop “organizing skills.” Armed with Obama’s 2012 campaign database, OFA plans to get out the vote for Democratic candidates it’s grooming to win back Congress and erect a wall of resistance to Trump at the other end of Pennsylvania Avenue.

It will be aided in that effort by the Obama Foundation, run by Obama’s former political director, and the National Democratic Redistricting Committee, launched last month by Obama pal Eric Holder to end what he and Obama call GOP “gerrymandering” of congressional districts.

Obama will be overseeing it all from a shadow White House located within two miles of Trump. It features a mansion, which he’s fortifying with construction of a tall brick perimeter, and a nearby taxpayer-funded office with his own chief of staff and press secretary. Michelle Obama will also open an office there, along with the Obama Foundation.

The 55-year-old Obama is not content to go quietly into the night like other ex-presidents.

Critical to the fight is rebuilding the ravaged Democratic Party. Obama hopes to install his former civil rights chief Tom Perez at the helm of the Democratic National Committee.

Perez is running for the vacant DNC chairmanship, vowing, “It’s time to organize and fight . . . We must stand up to protect President Obama’s accomplishments,” while also promising, “We’re going to build the strongest grassroots organizing force this country has ever seen.”

The 55-year-old Obama is not content to go quietly into the night like other ex-presidents.

“You’re going to see me early next year,” he told his OFA troops after the election, “and we’re going to be in a position where we can start cooking up all kinds of great stuff.”

Added the ex-president: “Point is, I’m still fired up and ready to go.”

Paul Sperry is the author of “The Great American Bank Robbery,” which details the link between race-based housing policies and the mortgage crisis.