Many on Wall Street have long argued that the banks did not generally break the law when they packaged shoddy mortgages and sold them to investors in the lead-up to the financial crisis of 2008.

But on Monday, in the starkest of terms, a federal judge dealt a strong blow to that version of history. She ruled that two banks misled Fannie Mae and Freddie Mac in selling them mortgage bonds that contained numerous errors and misrepresentations.

“The magnitude of falsity, conservatively measured, is enormous,” Judge Denise L. Cote of Federal District Court in Manhattan wrote in a scathing 361-page decision.

The ruling came in a closely watched case brought by the government against the Japanese bank Nomura Holdings and Royal Bank of Scotland. They were the only two of 18 financial firms that took their case to trial, arguing that it was the housing crash, and not deceptive loan documents, that caused the bonds to collapse.