Weinberg was born on 8 December 1919 to a Jewish family in Warsaw. His father, Shmil (Szmuel or Samuil Moiseyevich) Weinberg (1882–1943, Russian),a well-known conductor and composer of the Yiddish theater, moved to Warsaw from Kishinev, Moldova (at that time a part of the Russian Empire) in 1916 and worked as a violinist and conductor for the Yiddish theatre Scala in Warsaw, where the future composer joined him as pianist at the age of 10 and later as a musical director of several performances. His mother, Sonia Wajnberg (née Sura-Dwojra Sztern, 1888–1943), born in Odessa, Ukraine (at that time a part of the Russian Empire), was an actress in several Yiddish theater companies in Warsaw and Lodz.The family had already been the victim of anti-semitic violence in Bessarabia – some members of his family were killed during the Kishinev pogrom. One of the composer's cousins (a son of his father's sister Khaya Vaynberg) – Isay Abramovich Mishne – was the secretary of the Military Revolutionary Committee of the Baku Soviet commune and was executed in 1918 along with the other 26 Baku Commissars.
Weinberg entered the Warsaw Conservatory at the age of twelve, studying piano under Józef Turczyński, and graduated in 1939. Two works (his first string quartet and a berceuse for piano) were composed before he fled to the Soviet Union at the outbreak of World War II. His parents and younger sister Esther, who remained behind, were interned at the Lodz ghetto and subsequently perished in the Trawniki concentration camp. Weinberg first settled in Minsk, where he studied composition under Vasily Zolotarev for the first time at the Conservatory there. At the outbreak of World War II on Soviet territory, Weinberg was evacuated to Tashkent (Central Asia), where he wrote works for the opera, as well as met and married Solomon Mikhoels' daughter Natalia Vovsi. There he also met Dmitri Shostakovich who was impressed by his talent and became his close friend. Meeting Shostakovich had a profound effect on the younger man, who said later that, "It was as if I had been born anew". In 1943, he moved to Moscow at Shostakovich's urging.
Once in Moscow, Weinberg began to settle down and to work energetically, as evidenced by his increasing opus numbers: approximately 30 works from 1943 until 1948. Several of Weinberg's works were banned during the Zhdanovshchina of 1948, and, as a result, he was almost entirely ignored by the Soviet musical establishment; for a time he could make a living only by composing for the theatre and circus. On 13 January 1948 Weinberg's father-in-law Mikhoels was assassinated in Minsk on Stalin's orders; shortly after Mikhoels's murder, Soviet agents began following Weinberg. In February 1953, he was arrested on charges of "Jewish bourgeois nationalism" in relation to the murder of his father-in-law as a part of the so-called "Doctors' plot": Shostakovich allegedly wrote to Lavrenti Beria to intercede on Weinberg's behalf, as well as agreeing to look after Weinberg's daughter if his wife were also arrested. In the event, he was saved by Stalin's death the following month, and he was officially rehabilitated shortly afterwards.
Thereafter Weinberg continued to live in Moscow, composing and occasionally performing as a pianist. He and Shostakovich lived near to one another, sharing ideas on a daily basis. Besides the admiration which Shostakovich frequently expressed for Weinberg's works, they were taken up by some of Russia's foremost performers and conductors, including Rudolf Barshai, Emil Gilels, Leonid Kogan, Kirill Kondrashin, Mstislav Rostropovich, Kurt Sanderling, and Thomas Sanderling.