LONDON—HSBC Holdings PLC is to be released from a controversial agreement that let it avoid U.S. criminal charges in 2012, after it was judged to have sufficiently improved its systems to keep out financial criminals.

The expiration of the five-year deferred prosecution agreement with the U.S. Justice Department is a win for the bank and Chief Executive Stuart Gulliver, who had sought to have the case cleared before he retires in February. It also heralds the end of a contentious relationship between HSBC and an independent...