Gosar was born in a working-class family in Logatec, Inner Carniola, in what was then the Austro-Hungarian Empire. His father was a shoemaker, and Andrej worked in his workshop two years, before enrolling to the Classical Gymnasium in Ljubljana in 1902. Between 1910 and 1918, he studied law at the University of Vienna, where he obtained his PhD.
In 1918, after the dissolution of the Austro-Hungarian Empire and the creation of Yugoslavia, he became a legal advisor to the temporary Provincial Government for Slovenia in matters of welfare and social policy. In this period, he joined the conservative-Catholic Slovene People's Party. In 1920, he was elected to the Constituent Assembly of the Kingdom of Serbs, Croats and Slovenes. In the early 1920s, he became an active trade unionist, serving as a legal expert in the Yugoslav Professional Union, the largest Christian Socialist trade union in Slovenia. In 1922, he was the co-founder of the Alliance of the Working People, a wide left wing platform that unified several political parties, from Christian Socialist groups to Communists, for the local elections. The platform gained significant support, and won the elections in Ljubljana, establishing a wide range welfare network. In 1925, he was re-elected to the National Assembly. Between 1927 and 1928, he served as Minister of Welfare in the coalition governments of Velimir Vukićević and Anton Korošec. In 1929, he was appointed to the State Legislative Council, an institution established during the royal dictatorship of Alexander I of Yugoslavia as a substitute for an elected parliament. He resigned in 1931, when the Slovene People's Party withdrew its support to the royal regime.
In 1929, he became professor of sociology and economy at the University of Ljubljana, and between 1935 and 1939, he served as dean of the Faculty for Technology. In the same period, he also became the president of the Yugoslav section of the International Paneuropean Union.
During the 1920s and 1930s, he published numerous treatises on economic and social policies. The most important of these were Essays on National Economy (1922), For A Christian Socialism (1923), Social Economy (1924). In his magnum opus, the treatise For A New Social Order, published in two volumes between 1933 and 1935, he defended a market economy with welfare regulations, and urged for a politics of "Christian Social activism". In the early 1920s,he was considered one of the leading theoreticians of the Christian Socialist wing of the Slovene People's Party. By the early 1930s, his theories came under attack from all sides: from the right, he was challenged by the corporativist Catholics around Ernest Tomec, Lambert Ehrlich and Josip Jeraj. From the left, he was seen with suspicion by exponents of the radical Christian Socialist youth, such as Tone Fajfar, Aleš Stanovnik and Edvard Kocbek. He was also criticized by classical liberal economists and by Marxist theoreticians, including Edvard Kardelj, the foremost theoretician of the Communist Party of Slovenia.
With the rise of Catholic integralism and corporatism in the late 1930s, Gosar's position in Slovene political Catholicism became marginal. In the last years before the Second World War, Gosar moved to a more centrist position, calling for a Christian Democratic re-alignment of the Slovene People's Party. He warned against authoritarian corporatism, fascism, and Marxism, calling for an "autonomist Christian solidarism", based on communitarian values. He was also one of the most consistent advocates of the autonomy of Slovenia within Yugoslavia. In 1940, he published a volume exploring the legal, economic, financial, political and social arguments for the creation of a "Banovina of Slovenia", based on the model of the autonomous Banovina of Croatia.
After the Axis invasion of Yugoslavia in April 1941, he refused to join the Liberation Front of the Slovenian People, because of its pro-Communist orientation. By late 1941, he broke with the underground leadership of the Slovene People's Party due to disagreements on the issue of the relations towards the Italian occupation regime; contrary to the party's main current, which supported some sort of tacit tactical agreement, Gosar disapproved of all kinds of collaboration with the occupation forces. Rejecting both the partisan movement and the collaborationist Slovene Home Guard, he became one of the leaders of the so-called "Catholic Centre", together with Jakob Šolar in the Province of Ljubljana, and Engelbert Besednjak and Virgil Šček in the Julian March. In 1944, he was arrested by the Nazi German authorities and sent to the Dachau concentration camp.
After the return in 1945, he was stripped of most of his pre-war academic functions by the new Communist regime; he was however allowed to continue teaching forest legislation at the Technical Faculty. After retirement in 1958, he published a personal memoir, in which he bitterly described his position in the decade 1935-1945 as "the voice shouting in the desert".
In 1967, he was awarded with the Pro Ecclesia et Pontifice by the Holy See.
He died in Ljubljana in 1970.