Marvin Traub — the legendary retail merchant who built Bloomingdale’s into a retail powerhouse in storied career that spanned more than 40 years — has died at the age of 87, officials at his office confirmed.

The visionary retail icon transformed retailing in the US in the 1970s and 1980s, energizing Bloomingdale’s with a theatrical flair that attracted a star-studded clientele that included Jacqueline Onassis, Ladybird Johnson and Queen Elizabeth II.

The market-savvy merchant prince died at his home in New York City with his family after being hospitalized just before July 4, a business associate told The Post.

Traub recently had been fighting bladder cancer, and founded a charity called Pin Down Bladder Cancer to raise awareness of the disease and fund research.

Famous for his seemingly inexhaustible energy, Traub had been working in the offices of his New York consulting firm, Marvin Traub Associates, as recently as two weeks ago, according to an associate.

After graduating from Harvard College and Harvard Business School, Traub soon took a position at Bloomingdale’s, which at the time was a laggard department store behind Macy’s, Gimbel’s, Altman’s and A&S.

Determined to revamp Bloomingdale’s from the beginning, Traub rose steadily through the ranks to become president in 1969 and chairman in 1978.

He is survived by his wife, Lee Laufer, and their three children, Andrew, James and Margaret, as well as four grandchildren.