More than 100 years ago, The Greatest Show on Earth made its premiere in The Greatest City in the World.

P.T. Barnum brought his spectacle to Brooklyn in 1871, grabbing headlines and drawing crowds while the Ringling Brothers gained notice for turning railroad cars into circus trains.

But it wasn’t until 1919 that the two merged, creating Ringling Brothers & Barnum and Bailey Circus. It debuted at Madison Square Garden on March 29 — marking the start of a tradition for generations of New Yorkers.

“It became a part of the rhythm of the city,” said historian Matthew Wittmann, author of “Circus and the City.” “Circus posters in New York City marked the start of spring the way tulips come up in April.”

The circus rolls into New York City for the last time on Thursday when it kicks off a 15-show run at the Barclays Center. The beloved big-top extravaganza is shutting down this year — a casualty of declining ticket sales, ballooning operating costs and changing entertainment tastes.

“It is the end of an era — I can’t think of many other forms of entertainment that have lasted as long as Ringling Brothers,” said Stephen Payne, a spokesman for Feld Entertainment, which runs the circus. “There has been a huge outpouring of support and we are looking forward to entertaining tens of thousands of fans.”

Ringmaster Johnathan Lee Iverson admitted he’s heartbroken “something this wonderful” is closing down.

“We are peddlers of joy,” said Iverson, who grew up on the Upper West Side and made history as the first African-American ringmaster in 1999. “We spread nothing but happiness through what we do. There is never a person who has come to a Ringling Brothers show who isn’t uplifted.”

This year’s show, titled “Out of this World” promises to transport the audience into space for an intergalactic adventure, filled with acrobats, aerialists, daredevils, clowns and exotic beasts.

In a sad irony, fans are racing to buy tickets for performances at the Barclays Center and the final shows at the Nassau Coliseum in May.

“I’m the president of the Circus Fans Association of America and I can’t get a ticket to the last show,” said Gary Payne of Waterbury, Connecticut, who has experienced a surge in membership applications over the last few weeks.

Payne has seen more than 1,000 circus shows including about 400 by Ringling Brothers. Attending a show in New York City adds to the excitement, he said.

“New Yorkers respond to a circus like few other places I have ever seen,” said Payne. “It’s a great deal of fun to sit in a receptive audience.”

During its heyday in the 1920s and 1930s, the circus drew about 1 million people when it opened in New York City, said Wittmann.

“They came to the biggest market in the country and it created momentum for their whole tour,” he said.

Over the years, New Yorkers have witnessed acts including: The Flying Wallendas; Gargantua the Great, a gorilla billed as “the world’s most terrifying creature”; the George Balanchine choreographed “Ballet of the Elephants”; and Teutonic animal trainer Gunther Gebel-Williams — known for his devotion to his big cats.

“When you went to the circus, you knew you were going to see something you hadn’t seen before — some wilder animal, some greater act,” said Wittmann.

Watching the elephants walk through the Midtown Tunnel from Queens to Manhattan became another city ritual for many.

Iverson recalled the first time he performed at Madison Square Garden.

“I felt complete and utter joy,” he said. “I felt the spirit of all those legends who had passed through that great arena.”

Wittmann said audiences are still fascinated by circus acts, but want to view them in a more intimate setting — rather than a cavernous, indoor stadium.

The circus also found itself battling with animal-rights activists inside and outside the courtroom over the treatment of its menagerie, especially the elephants.

The ASPCA and other groups sued the circus in 2000, claiming it used cruel methods to train and control elephants. The case lasted more than a decade with the courts ultimately siding with the circus, saying the plaintiff was paid by the groups. Feld countersued and settled for millions of dollars.

In 2011, Feld and the U.S. Department of Agriculture reached a $270,000 settlement agreement for alleged violations of the Animal Welfare Act.

But the criticism continued and the circus moved its Asian elephants out of the spotlight to its Center for Elephant Conservation in Florida last year.

In a message to fans on the official circus website, owner Kenneth Feld said ticket sales dropped dramatically after the elephants were taken out of the show.

“This country’s great traditions are being lost,” said Payne of the Circus Fans Association. “We should do everything we can to save this national treasure.”

The show, however, must go on.

Performers arrived in the city this week fresh off a stint in Philadelphia and were ready to dazzle.

“Who else can say they had a 146-year run?” said Iverson.

The talented tenor is mulling his next move. His wife is the production manager of the show and their two children have grown up with them on the road.

He said he would love to be part of a Broadway production or even a talk show.

“I think Kelly Ripa needs a friend really badly,” Iverson laughed.