OSLO, Norway (AP) _ Einar Gerhardsen, a trade unionist turned politician who became the main architect of Norway's welfare state and led three post-war Labor governments, died today. He was 90.

Gerhardsen, a largely self-taught son of a construction worker, also headed the Labor Party for 20 years, and was imprisoned by the Nazis when they invaded Norway while he was serving as mayor of Oslo.

An official statement distributed by the Norwegian national news agency NTB said Gerhardsen died at 2:15 a.m. today at Lilleborg nursing home, where he was admitted in July after being hospitalized with heart trouble. His three children were at bedside.

The cause of death was not disclosed.

''Einar Gerhardsen became the most towering Norwegian personality of the 20th century. I'm convinced that this will also be the historical judgment,'' Prime Minister and Labor Party leader Gro Harlem Brundtland said today.

''He was the prime architect and constructor of the welfare society growing out of the 1930s and for the reconstruction of our country after World War II,'' she said in a statement.

Einar Henry Gerhardsen was born May 10, 1897 in Asker just south of the Norwegian capital. The family later moved to Oslo.

As a teen-ager, Gerhardsen entered the Young Socialist movement and soon became active in trade union and Labor Party activities.

Gerhardsen was elected Mayor of Oslo and was acting chairman of the Labor Party when Germany invaded Norway on April 9, 1940. He was imprisoned two years later and held until the war ended.

Upon his release on May 8, 1945, Gerhardsen resumed his position as Oslo mayor and was elected Labor Party chairman.

In June 1945 he was asked by the late King Haakon VII to form Norway's first post-war Cabinet, a coalition of all major political parties. Gerhardsen formed his first Labor Party government that October when the party won a majority in Parliament.

He continued as premier after the 1949 general elections, and resigned in November 1951 for personal reasons. He left the post to his friend, Oscar Torp, and served himself as president of Parliament.

In January 1955, Gerhardsen again took over as premier, stepping down a decade later when a non-socialist coalition headed by Center Party leader Per Borten assumed power.

Beyond elementary school and two years at a technical evening school in Oslo, Gerhardsen never had any formal education.

He read extensively, however, and in 1928 spent six months in Austria and Germany on a Norwegian scolarship studying the socialist movement.

He attended the founding congress of the first Communist International in Moscow in 1920.

As premier he worked to estasblish strong relations with foreign countries and led Norway into NATO in 1949.

Gerhardsen always held a strong position in Norway and was respected far beyond the ranks of his own party circles. Without relinquishing his own political ideas, the tall blue-eyed man always stressed the importance of cooperation during the post-war period of reconstruction.

Even his political opponents conceded he had a winning and sympathetic manner and was an excellent speaker who always drew large crowds at public meetings.

In 1932 Gerhardsen married Werna Koren Christie who died in 1970. They had three children, sons Rune and Truls and a daughter, Torgunn. Mrs. Gerhardsen was also active in the Labor movement and served in the Oslo City council.

Rune is a politician in Oslo. In local elections last Monday, he lost a contest for head of the politically powerful post as head of the Oslo regional coucil.