SAN FRANCISCO — Trouble is brewing in Gotham City. The Riddler is on the loose. The Penguin is up to no good. A damsel is in distress.

But never fear. Batkid is coming to the rescue.

San Francisco will be transformed into Gotham on Friday as 5-year-old Miles, who has successfully battled leukemia, will get to save the day as the superhero Batkid. The event is the culmination of a youngster’s fertile imagination, the efforts of the Make-A-Wish Foundation and the power of social media.

About 12,000 people have signed up to help make the boy’s fantasy of being a caped crusader come true, thanks to the feel-good story going viral on the Internet. They will cheer on the pint-size champion as he foils elaborately staged, nefarious plots and captures evildoers throughout San Francisco, uh, Gotham.

“We knew a superhero wish would be really cool, but it’s kind of surreal to see what’s happened,” said Patricia Wilson, executive director of the Make-A-Wish Greater Bay Area chapter. “Receiving a wish is a life-transforming experience for any child, and it’s apparently the case for everyone who wants to be involved in this wish.”

The foundation, which turns dreams into reality for seriously ill kids, is not releasing much information about the boy before Friday’s event. But masked superheroes are supposed to be mysterious, right?

Make-A-Wish has said that Miles is from Siskiyou County, near the Oregon border. And while he’s a big fan of Batman, Miles has been showing his own, very-real heroism. He was diagnosed with leukemia as a 1-year-old, and has been fighting the disease ever since.

Miles now is in remission. So his day as Batkid is a moment to celebrate.

“This wish has meant closure for our family,” said Miles’ mother, Natalie, in a foundation news release.

Wilson isn’t sure how word started to spread. She suspects it came after her request for volunteers to help with the “capers” that Miles would thwart was posted on someone’s Facebook page.

“You know it’s big when the Goodyear Blimp people are calling us,” Wilson said.

Eric Johnston, a Bay Area inventor and acrobat, will play the role of Batman as he assists (and reassures) Batkid throughout the day. He and his wife, Sue Graham Johnston, who has the damsel role, even created Bat-style gadgets that include a wrist device that will project previously recorded messages from San Francisco Police Chief Greg Suhr for Batkid throughout the day.

“The chief really hams it up,” Johnston said. “I’d cast him in a movie.”

Johnston met Miles earlier this week and gave him acrobatic lessons on Thursday. The boy, he said, knows he’s on a “Batman trip,” but has no understanding of the scope of Friday’s event.

“He’s an excellent superhero because he’s a totally mild-mannered kid when the mask is off,” Johnston said. “But when he puts on the armored Batsuit, he’s uncontainable. He shines.”

When Stefania Pomponi, founder and president of social media agency Clever Girls Collective, read about Batkid online, and saw the adorable photo of Miles in Batman garb, she had one thought: This is going to be huge.

She volunteered her agency’s services to manage an online campaign, passing the word through the 6,000 “influencers” in their network. They created a Twitter handle — @PenguinSF — where they assumed the Penguin character, playfully taunting Miles to gin up interest in Friday’s festivities.

“Social media is just word-of-mouth,” Pomponi said. “It just allowed this story to pick up steam.”

There’s even a Batkid Photo Project on Facebook where people from around the world are posting pictures in support of Miles.

Andrew Farago, curator of the Cartoon Art Museum in San Francisco, reached out to cartoonists and DC Comics, asking for Batman-related memorabilia and original artwork for the boy.

The first to respond was Graham Nolan, who drew the Batman series for much of the 1990s and is co-creator of the Bane villain character. “And the next day, he completed this amazing drawing for Miles that has Batkid versus Bane,” Farago said.

Nolan signed it: “For Miles, a real superhero!”

“We certainly all were children who had dreams of being a superhero and being larger than life,” Farago added. “But I think this has touched people because most of us have never had to overcome the obstacles that this boy has.”

Miles, oops, we mean Batkid, has a full day of adventures scheduled to frustrate the bad guys.

It will begin at 10 a.m. with Suhr issuing the call that Batkid is needed. Traveling by Batmobile, the masked boy will rescue the distressed damsel — is there any other kind of damsel? — from the Hyde Street cable-car tracks.

Then, Batkid will apprehend the Riddler in the act of robbing a bank vault. Then a flash mob will alert Batkid that the incorrigible Penguin has kidnapped Giants mascot Lou Seal. Our hero, who will rescue the mascot at AT&T Park. Then it’s on to City Hall where Mayor Ed Lee will present Batkid with a key to San Francisco/Gotham and most of the volunteers will be present to cheer for Batkid.

The Greater Bay Area chapter of Make-A-Wish plans about 350 wishes each year. Wilson hopes the exposure will ﻿help them create wishes for more kids. But what everyone hopes for most, of course, is that Miles just enjoys his day.

“He’s about to get a personal, action-hero adventure like no one has ever had before,” Johnston said. “And he deserves it.”