He was born in a Slovene family in the village of Slap ob Idrijci near Sveta Lucija (now Most na Soči), in what was then the Austro-Hungarian County of Gorizia and Gradisca (now in Slovenia). He attended high school in Tolmin and Gorizia. In the late 1920s, when his native region was part of Italy, Kosmač joined the militant anti-fascist organization TIGR. In 1930, he was arrested by the Italian Fascist authorities, but released the next year. He fled to the Kingdom of Yugoslavia, and settled in Ljubljana. In 1938, he was granted a scholarship granted by the French government, and he moved to Paris, where he worked for the Yugoslav embassy. In 1940, he fled to London, where he worked at the BBC World Service. In 1943, he went to Cairo, and in 1944 to Nazi-occupied Yugoslavia, where he joined the Yugoslav partisan resistance.
After World War II, he worked as a reporter and a screenplayer for the emerging Slovenian film production industry. Among other, he wrote the screenplay for the film On Our Own Land. In 1956, he settled in the coastal resort town of Portorož, where he spent the rest of his life. In 1961, he became a member of the Slovenian Academy of Sciences and Arts. He died in Ljubljana, and was buried in his native village. In 1980, he was posthumously granted the Prešeren Award, the highest award for artistic achievement in Slovenia.
Kosmač is renowned mostly for his short stories, which are frequently praised for their subtle psychological depth. He started writing in the late 1930s, publishing short stories in the literary journal Sodobnost, edited by the literary critic Josip Vidmar. His early works show an affinity to other contemporary Slovene authors who embraced a style known as social realism: Prežihov Voranc, Miško Kranjec, Anton Ingolič, Tone Seliškar, Mile Klopčič, Bratko Kreft, Ivan Potrč and others.
After World War II, he gradually turned away from social realism, and was among the first Slovene authors to include modernist features in his prose, especially surrealism. His later prose, which he is most renowned for, has frequently been considered a type of magical realism.