The Royal Bank of Scotland has already paid out tens of billions of dollars in penalties following the global financial crisis. Now, it's paying $5 billion more in a bid to draw a line under the crisis.

The British bank has reached an agreement "in principle" with the US Department of Justice to end the department's investigation into allegations it sold risky loans worth billions between 2005 and 2007, it said in a statement on Thursday.

Under the proposed settlement, RBS (RBS) will pay a penalty of $4.9 billion. The deal is yet to be finalized, and will be subject to the bank and the DOJ entering into a legally-binding agreement.

Including the penalty announced Thursday, RBS has paid out roughly £21 billion ($28.4 billion) in settlements and fines following the 2008 global financial meltdown.

Related: RBS makes a profit for the first time in a decade

The settlement marks a "milestone moment" for the bank, CEO Ross McEwan said in a statement.

"Reaching this settlement in principle with the US Department of Justice will, when finalized, allow us to deal with this significant remaining legacy issue and is the price we have to pay for the global ambitions pursued by this bank before the crisis," he said.

The size of the settlement -- expected to be the last major penalty for the bank -- was lower than analysts had feared. Some predicted RBS might have to pay around $10 billion.

The bank's shares jumped as much as 6.5% in London following the announcement.

Related: RBS makes a profit for the first time in a decade

The British government owns more than 70% of RBS, a legacy of a £45 billion ($61 billion) taxpayer bailout of the bank in 2008. The DOJ settlement could clear the way for the government to offload its stake.

"Our policy remains to return the bank to private hands as soon as we can achieve fair value for the shares, recognizing that fair value could well be below what the previous government paid for them," UK Treasury chief Philip Hammond said in April.

RBS said earlier this year that it earned £752 million ($1 billion) in 2017, its first profit after nine consecutive years of losses totaling £58 billion ($79 billion).

RBS agreed to pay $5.5 billion last year to settle a separate investigation by the US Federal Housing Finance Agency. The bank said around $3.5 billion of the DOJ settlement would be covered by existing provisions, with the rest accounted for by an "incremental charge" in the second quarter of 2018.

-- Alanna Petroff contributed reporting.