WASHINGTON — A pair of luxurious waterfront compounds outside New York and Washington have for decades been a retreat for Russian diplomats, places to frolic in the water, play tennis and take lengthy steam baths.

On Thursday, Obama administration officials described the compounds differently: as beachside spy nests sometimes used by Russian intelligence operatives to have long conversations on the sand to avoid being ensnared by American electronic surveillance.

They ordered all Russians out of the compounds within 24 hours.

The move was one of a number of retaliatory measures the White House announced in response to what it called a Russian campaign to wreak havoc on the presidential election, and to what it said was systemic harassment of American officials in Russia.

Besides the shuttering of the two compounds, administration officials announced the expulsion by Sunday of 35 unnamed Russian officials — and their families — who they said were working undercover as spies.