The powerful prime minister of Qatar finally has a New York home. Sheik Hamad bin Jassim bin Jaber Al-Thani has bought real estate tycoon Aby Rosen’s famed East 71st Street mansion for $47 million.

Sources exclusively tell Page Six that Sheik Hamad in June quietly purchased the townhouse at 22 E. 71st St., famed for the lavish parties thrown there by Rosen, who never lived there.

One source said, “The deal was done in huge secrecy without a broker. The house has been purchased through an LLC, Tower Management Holdings, to protect the identity of the buyer, Sheik Hamad, who has been looking to purchase a New York property.”

Hamad had eyed expat socialite Denise Rich’s Upper East Side apartment, but was shunned by the co-op board because he rolls deep with two wives, 15 children and a gun-toting security detail, The Post reported. We exclusively revealed in July that music mogul David Geffen then scooped up Rich’s pad for $54 million.

And as The Post reported last month, the sheik had also considered the city’s most expensive penthouse, which would have seen him parting with nearly $100 million for a two-story pad atop the soaring new One57 tower across the street from Carnegie Hall.

But sources tell us he decided against the apartment “because he has a huge entourage and the building only had two elevators.”

Hamad also reportedly planned to spend $31 million on two apartments owned by late copper heiress Huguette Clark, but was rejected by the co-op board.

Rosen, whose company owns the Seagram Building and Lever House, had listed the spectacular 22,000-square-foot, five-floor neo-Italian Renaissance mansion — one of the largest townhouses in New York — initially in 2008 for an eye-watering $75 million, but dropped the price after refusing two offers of over $60 million.

Rosen didn’t respond to e-mails last night, and Alison Hirsch, the attorney listed for the buyer, didn’t return calls and e-mails.