The Main Directorate of State Security (Russian: Glavnoe Upravlenie Gosudarstvennoi Bezopasnosti, Главное управление государственной безопасности, ГУГБ, GUGB) was the name of the Soviet intelligence service and secret police from July 1934 to April 1943. It was run under the auspices of the Peoples Commissariat of Internal Affairs (NKVD). Its first head was first deputy of People's Commissar of Internal Affairs (then - Genrikh Yagoda), Commissar 1st rank of State Security Yakov Agranov.
The Main Directorate of State Security evolved from the Joint State Political Directorate (or. OGPU). On February 3, 1941, the Special Sections (or. OO) of the GUGB-NKVD (responsible for counter-intelligence in the military) became part of the Army and Navy (RKKA and RKKF, respectively). The GUGB was removed from the NKVD and renamed People's Commissariat of State Security or NKGB.
Following the outbreak of World War II, the NKVD and NKGB were reunited on July 20, 1941 and counter-intelligence was returned to the NKVD in January 1942. In April 1943 it was again transferred to the Narkomat of Defence and Narkomat of the Navy, becoming SMERSH (from Smert' Shpionam or "Death to Spies"); at the same time, the GUGB was again separated from the NKVD as NKGB.
By the end of 1937 GUGB was the most powerful and influential organ in NKVD structure. GUGB departments (or Sections) dealt with - intelligence, internal security, counter-intelligence, protection of government and secret communications.
First chief of GUGB was Yakov Agranov, Commissar 1st rank of State Security and first deputy of People's Commissar of Internal Affairs. Next chief of GUGB from April 15, 1937 to September 8, 1938 was komkor Mikhail Frinovsky, he was succeeded by Lavrenty Beria, then just promoted to Commissar 1st rank of State Security. When Beria become People's Commissar of Internal Affairs (head of NKVD), Commissar 3rd rank of State Security Vsevolod Merkulov become his first deputy and new and last head of GUGB.