Target Corp will exit the Canadian market after less than two years in a surprise retreat that will throw more than 17,000 employees out of work and trigger a $5.4 billion quarterly loss.

Shares of the U.S. discount retailer, which was granted creditor protection for its money-losing Canadian subsidiary, at one point rose more than 4% on the move. The stock was up 2.2% at $75.94 in afternoon trade on the New York Stock Exchange.

The company announced on Thursday it is shutting all of its 133 Canadian stores and said it expects to report about $5.4 billion in pretax losses for its fourth quarter, which finishes at the end of January. Losses are mostly due to the writedown of the Canadian investment, along with exit costs and operating losses.

Minneapolis-based Target, the No. 2 discount chain in the United States, has struggled in Canada since its March 2013 launch. It faced huge supply chain problems due to a myriad of problems at its warehouses, poor communication with headquarters and the use of inexperienced staff. That left stores poorly stocked and selection limited, disappointing shoppers who had eagerly anticipated its arrival in a market where the discount space was long dominated by Wal-Mart Stores Inc.

Target had said in November it would review the future of the Canadian business after the holiday season. Stores checked by Reuters in Vancouver, Toronto and Ottawa around Christmas showed only moderate traffic and Chief Executive Brian Cornell said he didn’t see the "step-change" in performance required to justify staying the course.

No matter how Target crunched the numbers it could not envision making profits until 2021, Cornell said. He told a conference call the company was "facing a decision to devote billions of dollars of additional resources for the Canadian segment without the realistic prospect of an appropriate return."

The move surprised some analysts who had expected Target to close its weakest stores and try to fix the rest. Before Thursday’s decision Target had sunk roughly $6 billion into the market, including around $2.5 billion in capital expenditure and $1.7 billion of losses to-date, Fitch Ratings said.

"Anything you could have gotten wrong in the playbook, they got wrong," said Antony Karabus, CEO of retail consultant firm HRC Advisory.

Target said exiting Canada would allow it to focus resources on the U.S. market, where it is recovering from a massive data breach during the holiday quarter of 2013. Target said comparable U.S. sales during the fourth quarter would likely rise 3%, up from its 2% forecast. It also raised its estimate for adjusted earnings per share in the quarter to $1.43 to $1.47, an upward revision of 6 cents.

Expectations Canadian retailers would benefit from the pullout helped lift their shares, with Canadian Tire up more than 5% at one point, and grocers Loblaw and Empire Co both up about 2%. Wal-Mart is also seen as a beneficiary and could look to pick up some of the abandoned locations, analysts said.

Target said it would look to grow in the United States by expanding its smaller format stores, including those in big cities.

But the failure in Canada raises serious doubts about the retailer’s long-term growth prospects, said Jim Danahy, director of the Centre for Retail Leadership at York University’s Schulich School of Business in Toronto.

"There isn’t a bigger implosion and it needs to be really understood this is entirely their fault," Danahy said.

Target had hired Eleven Points Logistics, a subsidiary of Pittsburgh-based Genco, to run its Canadian warehouses.

The company had also reached a long-term wholesale agreement with Empire Co’s Sobeys to supply it with groceries in Canada. A spokesman for Sobeys said the loss of the account would not have a material impact on its results. Genco could not immediately be reached for comment.

Former Target and Eleven Points employees had told Reuters about a laundry list of problems at the warehouses, stores, and headquarters, especially in the first year. They said a combination of new technology and systems, inexperienced hires and poor training all contributed to supply chain woes.

Barcodes on many items did not match what was in the computer system, they said, causing massive warehouse logjams, while store backrooms were stacked from "floor to rafters," making it difficult to locate products to put on shelves.

Target said stores would remain open during liquidation, and that with court approval it would pay all of its Canadian employees a minimum of 16 weeks of compensation.