Struggling US auto giant General Motors on Tuesday signed a binding agreement to sell Saab Automobile to Swedish sports carmaker Koenigsegg but the deal rests on the government providing necessary guarantees.

“General Motors Co. today confirmed it has signed a stock purchase agreement with Koenigsegg Group AB regarding the sale of 100 percent of the shares of Saab Automobile AB,” the company said in a statement.

The announcement follows a tentative agreement between the two parties on June 16 and Saab now moves closer to returning to Swedish ownership after an unhappy, largely unprofitable two decades under American management.

“We will continue to work with all parties to define the final details and ensure a fast closure of the deal,” GM Europe CEO Carl-Peter Forster said in a statement.

“The closure of the deal is contingent on the funding commitment from the European Investment Bank (EIB), guaranteed by the Swedish government,” he added.

Matts Carlsson, an automotive analyst with Gothenburg’s Management Institute, said the statement was aimed at “building confidence” in the market and amongst Saab’s customers.

But before winning the hearts of potential car buyers, Koenigsegg has to convince the Swedish government of the viability of its business plan for the iconic automaker.

The niche sports carmaker is seeking a 600-million-euro (848-million-dollar) loan from the European Investment Bank but wants the Swedish government to act as a guarantor.

“It is positive that the question over Saab’s ownership is getting clearer but there are still several steps to be taken before all this is finished. Koenigsegg has to find more private capital,” said Secretary of State for Industry, Joeran Haegglund.

Carlsson said that another three billion kroner (292 million euros, 414 million dollars) has to be found to ensure that the government does its part and “that will be an object of discussion right up until the end.”

Koenigsegg Group, founded in 1994 by Swedish businessman Christian von Koenigsegg, has just 45 employees and produces 18 high-end sports cars a year at more than a million euros (1.4 million dollars) each.

Saab, by contrast, employs 3,400 people in Sweden alone and sold just over 93,000 cars worldwide in 2008.

Christian von Koenigsegg said he wants “to transform Saab into a stand-alone vibrant entrepreneurial company and make it ?sustainable? by making it profitable.”

GM said it expected the transaction to be completed by the end of the year while Saab said it expected to exit “shortly” from bankruptcy protection.