WASHINGTON — With only 21 days in the Whitehouse, the Obama administration struck back at Russia on Thursday for its efforts to influence the 2016 election, without presenting any evidence that can justify the unprecedented action, ejecting 35 Russian intelligence operatives from the United States and imposing sanctions on Russia’s two leading intelligence services.obamaThe administration also sanctioned four top officers of one of those services, the military intelligence unit known as the G.R.U., which Obama believes ordered the attacks on the Democratic National Committee and other political organizations.The expulsion of the 35 diplomats was in response to the harrassment of American diplomats in Russia, officials said. But some individuals involved are believed to be linked to cyberactivity, according to two officials briefed on the intelligence. In addition, the State Department announced the closure of two “recreational facilities” — one in New York, another in Maryland — that it said were used for Russian intelligence activities, although officials would not say whether they were specifically used in the election-related hacks.In a sweeping set of announcements, the United States also released samples of malware and other indicators of Russian cyberactivity, including network addresses of computers commonly used by the Russians to launch attacks. Taken together, the actions amount to the strongest American response ever taken to a state-sponsored cyberattack aimed at the United States.bbxeryrThe sanctions were in part intended to box in President-elect Donald J. Trump. Mr. Trump has consistently cast doubt that the Russian government had anything to do with the hacking of the D.N.C. or other political institutions, saying American intelligence agencies could not be trusted and suggesting that the hacking could have been the work of a “400-pound guy” sitting in his bed.Mr. Trump will now have to decide whether to lift the sanctions on the Russian intelligence agencies when he takes office next month, with Republicans in Congress among those calling for a public investigation into Russia’s actions. Should Mr. Trump do so, it would require him to effectively reject the findings of his intelligence agencies.

Asked on Wednesday night at his Mar-a-Lago estate in Palm Beach, Fla., about reports of the impending sanctions, Mr. Trump said: “I bladimir-puttinthink we ought to get on with our lives. I think that computers have complicated lives very greatly. The whole age of computer has made it where nobody knows exactly what is going on. We have speed, we have a lot of other things, but I’m not sure we have the kind, the security we need.”

President Obama, in a statement, put in a subtle dig at Mr. Trump’s unwillingness to talk about Russia’s role. “All Americans should be alarmed by Russia’s actions,” he said. He said he acted after “repeated private and public warnings that we have issued to the Russian government” and called the moves “a necessary and appropriate response to efforts to harm U.S. interests in violation of established international norms of behavior.”

The samples of malware were in what the Obama administration called a “joint analytic report” from the F.B.I. and the Department of Homeland Security that was based in part on intelligence gathered by the National Security Agency. A more detailed report on the intelligence, ordered by President Obama, will be published in the next three weeks, though much of the detail — especially evidence collected from “implants” in Russian computer systems, tapped conversations and spies — is expected to remain classified.

In Moscow, there was a sense that the Obama administration was trying to take unseemly last-minute revenge against Russia and President Vladimir V. Putin.

“We regret that this decision was made by the U.S. administration and President Obama personally,” Dmitri S. Peskov, the spokesman for Mr. Putin, told reporters. “As we have said before, we believe such decisions and such sanctions are ungrounded and illegal from the point of view of international law.”