Harry Potter waved his magic wand — and a Broadway theater everybody hates will be home to a show everybody loves.

“Harry Potter and the Cursed Child,” a runaway hit in London, will open in New York in the spring of 2018 at the barn-like Lyric Theatre, which, under that and several other names, housed some of the most expensive flops in Broadway history.

Producers Sonia Friedman and Colin Callender confirmed their choice after The Post learned the theater would undergo extensive renovations when the current tenant, Cirque du Soleil’s “Paramour,” closes in April.

The Ambassador Theatre Group, which owns the Lyric, is shelling out tens of millions of dollars to tailor the theater specifically for “Harry Potter.”

“They made us an offer we simply couldn’t refuse,” Friedman says.

“I’m delighted we’re one step closer in bringing ‘Harry Potter and the Cursed Child’ to Broadway and very excited by the proposed plans,” says J.K. Rowling.

Landing “Harry Potter” is a major coup. Broadway’s three other landlords — the Shuberts, the Nederlanders and Jujamcyn — had hotly pursued the show, offering up their best theaters. Sources say they were shocked to lose out to the Ambassador group.

The Lyric has 1,900 seats, making it the second-largest theater on Broadway. Producers complain that shows often get swallowed up in its vastness. To make the theater more intimate for “Harry Potter,” 400 seats will be removed and the back wall of the auditorium will be moved closer to the stage.

“They’re essentially creating a new theater within the old theater,” Callender says.

The plan also calls for shifting the theater’s entrance, now lost amid the tumult of 42nd Street, to 43rd Street. There are no other theaters on 43rd Street, so “Harry Potter,” with its glittering marquee topped off with a giant owl’s nest, will dominate the blocks between Broadway and Eighth Avenue.

“The fact that we won’t be sharing the street with other theaters and marquees was another enticement,” Friedman says.

That stretch of 43rd Street is one of the few sleepy spots left in Times Square. Aside from the Lyric, the only other buildings of note are the old New York Times offices and the down-market Hotel Carter. But when “Harry Potter and the Cursed Child” opens in 2018, the street will be swarming with Potter fans. The play, performed in two parts, is an all-day affair, running nearly six hours with breaks.

‘I think this show could run 30 years, maybe forever.’ - Broadway insider

“Harry Potter and the Cursed Child” has caused a ticket-buying frenzy in London. The advance sales exceed $50 million, the highest in London theater history. Friedman and Callender recently released 60,000 more tickets. They were snapped up within 15 minutes.

Broadway insiders think the demand will be even greater in New York.

“I think this show could run 30 years, maybe forever,” one says.

Ambassador Theatre Group apparently thinks so, too. In addition to the multimillion-dollar renovation of the Lyric, the company is paying Cirque du Soleil more than $20 million to vacate the theater in April, sources say.

The Lyric Theatre, originally known as the Ford Center, is, in fact, a combination of two theaters from the early 20th century: the Apollo on 42nd Street and the Lyric on 43rd. Disgraced impresario Garth Drabinsky combined them in 1997 for his musical “Ragtime.” But “Ragtime” wasn’t the blockbuster he’d hoped for. When his company went bankrupt, and he went to jail in Canada for fraud and forgery, “Ragtime” collapsed.

Since then, the Lyric’s tenants have included such bombs as “The Pirate Queen,” “Hot Feet” and “Young Frankenstein.” Its most notorious tenant — “Spider-Man: Turn Off the Dark” — lost about $60 million.

“Harry Potter” should erase the theater’s status as Broadway’s white elephant.

Christine Jones, who designed the sets for “Harry Potter,” will be deeply involved in renovating the theater. She’s picking out the color of the paint on the walls as well as the carpet in the lobby and the auditorium. All will be done in the style of the Hogwarts School of Witchcraft and Wizardry.

“When you step over the threshold of the theater, you will be entering the world of Harry Potter,” Callender says.

He and Friedman say that, at 1,500 seats, the reconfigured Lyric will still allow them flexibility with ticket prices. Rowling has been adamant that “Harry Potter” be “accessible to everyone,” says Friedman.

They’ve yet to work out New York pricing, but in London, prices for both parts of the play range from $40 to $176, a bargain on Broadway, where orchestra seats for “Hamilton” are $850.

“And the less expensive seats are scattered throughout the theater,” says Friedman. “They’re not all in the balcony.”