Rock legends including the Rolling Stones and Pink Floyd’s Roger Waters “put their egos away” and mingled backstage at the historic “12-12-12” concert at Madison Square Garden.

Sources tell us space was tight Wednesday because, with more than 20 artists, the rock gods “had to ditch their entourages and just get along.”

One spy told us, “Usually Mick Jagger, Ronnie Wood, all the Rolling Stones get their own dressing rooms, but this time the band had to share one. All the acts, including Kanye West, were banned from bringing large entourages, as there was simply not enough room.

“But it was a nice atmosphere backstage, everyone was in a good mood, and many of the big rock acts were excited to see The Who, because they tour so rarely. All came out at the side of the stage to watch, Jon Bon Jovi was even in the photographers’ pit to shoot them.”

As well as sharing a tiny dressing room, the Stones settled for a lower billing. The source continued, “The Stones confirmed late, by which time they were told, ‘We only have a 15-minute slot, and you’ll be earlier in the show.’ They agreed to take it.” Another source told us, “It was like an old English rockers high school reunion back there — they get on pretty well but still have strong opinions about each other.

Jon Stewart came rushing over to Roger Waters. It was nice to see Stewart, who said he was a fan, at a loss for words for once. He said to Waters, who’s at least a foot taller than him, ‘Why are you so tall?’ ” Waters shot back: “Why haven’t you invited me on your f – – – ing show?”

Waters also poked fun at Stewart for once saying that listening to his band, Pink Floyd, reminds you “of where you hid your pot at 15.” Waters joked, “So what’s this about Pink Floyd and pot?”

Also seen wandering backstage greeting the other rock legends were Billy Joel, Harvey Weinstein, Lorne Michaels and Seth Meyers.

MSG head Jim Dolan and his band played a Lavo after-party, where guests included Billy Crystal, Paul Allen, Chris Martin, Michael Stipe, Chris Rock and Steve Buscemi.