Target will abandon its ill-fated expansion into Canada less than two years after its launch, the U.S. discount retailer said on Thursday in a surprise full retreat that will put more than 17,000 employees out of work and cost the company billions in write downs.

Target's shares rose after the company said it will seek court protection from creditors in Canada for the money-losing subsidiary and shut all its 133 stores in the country.

The company said it expects to report about $5.4 billion in pretax losses for its fourth quarter, which finishes at the end of January, mostly due to the writedown of the Canadian investment, along with exit costs and operating losses.

"After a thorough review of our Canadian performance and careful consideration of the implications of all options, we were unable to find a realistic scenario that would get Target Canada to profitability until at least 2021," CEO Brian Cornell said in a statement.

Read MoreWhere Target went wrong in Canada



In the same statement, Target also said it expected to report fourth-quarter comparable-store sales growth of 3 percent, versus its prior forecast of 2 percent growth.

Target has struggled in Canada since its 2013 launch, facing huge supply chain problems that left stores thinly stocked, disappointing shoppers who had eagerly anticipated the retailer's move into the country, where the discount space had long been dominated by Wal-Mart Stores.

The company said in November it would review the future of the Canadian business after the holiday season.