Chip Somodevilla via Getty Images U.S. President Barack Obama answers questions during a news conference in the Brady Press Breifing Room at the White House December 16, 2016 in Washington, DC.

The United States expelled 35 Russian diplomats and closed two Russian compounds in New York and Maryland in response to a campaign of harassment against American diplomats in Moscow, a senior U.S. official said on Thursday.

The move against the diplomats from the Russian embassy in Washington and consulate in San Francisco is part of a series of actions announced on Thursday to punish Russia for a campaign of intimidation of American diplomats in Moscow and interference in the U.S. election.

The Obama administration was also announcing on Thursday a series of retaliatory measures against Russia for hacking into U.S. political institutions and individuals and leaking information to help President-elect Donald Trump and other Republican candidates, two U.S. officials said.

Trump, who takes office on Jan. 20, has called for better relations with Russia. It was not clear if he will be able to immediately overturn the measures announced on Thursday.

The Russian diplomats would have 72 hours to leave the United States, the official said. Access to the two compounds, which are used by Russian officials for intelligence gathering, will be denied to all Russian officials as of noon on Friday, the senior U.S. official added.

“These actions were taken to respond to Russian harassment of American diplomats and actions by the diplomats that we have assessed to be not consistent with diplomatic practice,” the official said.

The State Department has long complained that Russian security agents and traffic police have harassed U.S. diplomats in Moscow, and U.S. Secretary of State John Kerry has raised the issue with Russian President Vladimir Putin and his foreign minister, Sergei Lavrov.

“By imposing costs on the Russian diplomats in the United States, by denying them access to the two facilities, we hope the Russian government reevaluates its own actions, which have impeded the ability and safety of our own embassy personnel in Russia,” the official said.

The U.S. official declined to name the Russian diplomats who would be affected, although it is understood that Russia’s ambassador to the United States, Sergei Kislyak, will not be one of those expelled.

(Reporting by Lesley Wroughton; Editing by Yara Bayoumy and Alistair Bell)