The battle between John Mayer and Taylor Swift nearly came to a head Tuesday at West Hollywood’s starry Tower Bar, when the ex-lovers unexpectedly and uncomfortably came face-to-face.

The confrontation came about at the same time Mayer told Rolling Stone this week that Swift’s song “Dear John,” reportedly about him, was “a really lousy thing” to do, “cheap songwriting,” humiliating and “bull[bleep].”

Swift, 22, entered the Tower Bar at Jeff Klein’s Sunset Tower Hotel on Tuesday night, and, a spy tells Page Six, it was “drama central” when the blond superstar was about to be seated and noticed that her onetime beau Mayer, 34, was dining with a friend nearby.

PHOTOS: TAYLOR SWIFT

“Taylor very visibly — in front of the entire restaurant — demanded to be moved to the other side,” our spy said. “The bar’s usually an oasis of calm and privacy for celebrities and power players, but this was drama central.”

Also spotted amid the unusual Tower Bar tension Tuesday were Klein with NBC head Robert Greenblatt, “The Amazing Spider-Man” co-stars and off-screen couple Emma Stone and Andrew Garfield, Sharon Stone, Scarlett Johansson and “Something’s Gotta Give” director Nancy Meyers.

Adding to the drama that night were “a gaggle of ladies at the bar who were acting rowdy,” and approached Stone and Garfield’s table. They were asked to leave, and one diner was overheard sniffing, “What do those girls think this is? The Soho House?”

Swift and Mayer were briefly linked in 2010 before she released her 2010 poison-pen ditty “Dear John” — with lyrics, “You are an expert at sorry/and keeping the lines blurry.” She never confirmed it was about the notorious ladies’ man.

But Mayer, who’s publicly bashed ex-lovers from Jessica Simpson to Jennifer Aniston, says in Rolling Stone, “I never did anything to deserve that [song]. It was a really lousy thing for her to do . . . I know she’s the biggest thing in the world, [but] that’s bull[bleep].”