He was born in Copenhagen into the poor household of shoemaker and leatherworker Matthias Hansen and his wife Anna Marie, who had been nursemaid for Prince Christian VII. He was the youngest son in the family, and there was not much money to spend on his upbringing. His parents sent him to train in business, but he wanted to draw. His mother used her connections at the royal court, and found some influential people who interested themselves in his education and training.
He was brought into training as a bricklayer, and at the same time he attended classes at the Academy of Art starting in 1766. He studied at the Academy under architect Caspar Frederik Harsdorff, but probably also received some training from Nicolas-Henri Jardin. He won the Academy’s small silver medallion in 1772-1773, the large silver medallion in 1774-1775, and the large gold medallion in 1779.
He was taken into Harsdorff's private studio where he worked on the construction of Frederik V's chapel at Roskilde Cathedral in 1780.
He received no travel grant from the Academy, in spite of his receiving the gold medallion. Instead he received economic support from Dowager Queen Juliane Marie and King Christian VII for a shorter tour, and he traveled out of the country starting in late 1782, travelling over Vienna and Venice to Rome, where he studied ancient Roman art. His student drawings from the trip are kept in the Academy’s Library to this day.
He returned home September 1784, and became a member of the Academy in 1785.
Shortly afterwards he was named to the position of Regional Architect for the Duchies of Schleswig and Holstein, with residence in Altona, a position for which he had applied in 1782. He held this position from 24 November 1784 until his retirement on 31 October 1844.
He was named titular Professor at the Academy in 1791. In 1792 he married Anne Margrethe Rahbek.
He prospered during his 18 years in Altona and Hamburg, with a private practice that made up for the meager earnings he made in his official position. He built fine houses for the well-to-do, both in town and out in the country, estates on Elbchaussee, and small churches. He designed many fine houses along Altona's elegant boulevard Palmaille, including some investment houses at his own expense, which helped boost his earnings substantially when sold. He used a simple Roman Palladio-style in his work.
When Harsdorff died in 1799 a number of public building projects were transferred to Hansen, among these the completion of Frederik's Church, also known as The Marble Church (Marmorkirken) in Copenhagen.
He returned to Copenhagen in 1804, where he lived until his death. He had a large, social household in a fabulously appointed apartment in Copenhagen. In 1808 he was named Professor of Architecture, Chief Building Director, and given the position of State Advisor (etatsråd). He held the title of Chief Building Director until his retirement.
Hansen was responsible for the building of the City Hall and Courthouse on Nytorv (1805–1815), and the rebuilding of Church of Our Lady (Vor Frue Kirke) along with the surrounding square (1811–1829), after the church was burned down during the bombing of the second Battle of Copenhagen in 1807.
He overtook Nikolaj Abraham Abildgaard's leading position at the Academy, and was chosen eight times as Director of the Academy, 1811–1818, 1821–1827, and 1830-1833.
He was responsible for the Town Hall and Court Building at the site of the old Waisenhus, which was completed in 1815. That same year Metropolitan School was completed on Frue Plads.
The other major work he did was the rebuilding of Christiansborg Palace, which had burned down during the fire of 1794. The chapel was completed in 1826, and the rest of the building was completed in 1828.
In 1823 his church in Hørsholm, on the site of the former Hirschholm Palace, was dedicated. In 1826 he was named ‘’Konferensråd’’. In 1830 he established a medallion to be given to young architects. He became titled with the Order of the Dannebrog in 1840.
His marble bust of sculptor Hermann Ernst Freund is in the Academy’s Assembly Hall, as is his portrait of artist Conrad Christian August Bøhndel.
He died at his home in Frederiksberg at the age of nearly 90, and is buried in the Church of Holmen in Copenhagen.Krummbek Manor, Lasbek, Germany (1803)
Det Hvide Palæ, Randbøldal, Denmark (1839)
Christiansborg Palace (2nd), Copenhagen, Denmark (1803−1828)
Copenhagen Court House, Copenhagen, Denmark (1815)
Hørsholm Church (1822–23)
Church of Our Lady (Copenhagen), Copenhagen, Denmark (1829)