Smersh (short for Smert' Shpionam (Death to Spies!)) was formed during the Great Patriotic War, to secure the rear of the active Red Army, on the front to arrest "traitors, deserters, spies, and criminal elements".
It was also used to maintain terror in the Red Army, keeping a violent and abusive displine system in place, within the Red Army as it fought the Wehrmacht. It was also used extensively after the war as well, especially in Eastern Europe. In all Soviet controlled territory, it was used to conduct Stalinist witch hunts, and to purge the new communitst parties, so that they would become nothing more than obedient puppet states, to be ruled from Moscow, and to do Moscow's bidding.
Smersh was also used to punish those with in the NKVD itself; it was allowed to investigate whom ever it wished within the NKVD structure, department and directorate heads were not immune from it, and if it found even the slight bit of evidence that they were somehow involved in what ever plot it was that week, they would be arrested, and tortured by Smersh, forced to sign fake confessions, put on a show trial, and either sent to the camps, or shot. Smersh would also often be sent out to find and kill defectors, double agents, etc.
One of its most notorious moments, was when they slaughtered a dozen or so Polish officers in eastern Poland, an atrocity that was later blamed on the Germans. Smersh was also used by INO (the NKVD's later KGB FCD, First Chief Directorate, responsible for forign intelligence operations outside of the USSR) to hunt down "enemies of the people" outside of Soviet Territory, this was including but not limited to, supporters of Leon Trotsky, White Guard units, White Bolsheviks, and others, as well as traitors.
Eventually, Smersh's activites, were slowed down, though never really ceased, though its name may have changed as the NKVD changed, its duties always remained the same.