The Justice Department contends in a civil lawsuit that Standard & Poor’s inflated the ratings on complex mortgage securities, hurting investors. A weapon of choice: the computer models deployed to help rate securities.

Such models, which analyze large amounts of data, frequently crop up in financial scandals.

Enron, the firm that collapsed in 2001, used them to help value some of its esoteric assets. A faulty model, in part, prompted JPMorgan Chase’s derivatives traders to make ill-advised bets that led to $6 billion in losses.

And they helped stoke the housing bubble. During the boom, Wall Street packaged trillions of dollars of loans into bonds and attached overly optimistic credit ratings to them in the process. S.& P. and competitors relied heavily on models — the models took into account economic assumptions and potential losses — to come up with ratings.

Accounts of the financial crisis have shown that credit analysts placed too much trust in their models. They routinely relied on historical projections that failed in an environment where home prices were falling fast.

The Justice Department contends it was more than just naïveté. The suit claims that S.& P. employees deliberately used models to produce inflated, fraudulent ratings.

S.& P. defends its practices, saying the suit is without factual and legal merit. Catherine J. Mathis, an S.& P. spokeswoman, says the Justice Department had not “shown actual adjustment to the models or other changes that were not analytically justified.”

S.& P., which created its own models, seemed to regularly update its models, affixing each release with a different number, as in computer software upgrades. Rating agencies made reference to models publicly, giving the impression that they had used scientific methods to arrive at their ratings.

The Justice Department paints a different picture. The government says S.& P. avoided use of more accurate models. The complaint asserts that S.& P. staff chose not to update computer programs because the changes would have led to harsher ratings, and a potential loss of business.

Rating agencies are paid to evaluate securities by the issuers. An issuer might decide not to use a rating if it were lower than those available from rivals. In that case, the credit rating agency might lose valuable fees.

According to the Justice Department, S.& P. started to tinker with its models relatively early in the housing boom.

As home prices soared and buyers clamored for properties, banks began to churn out more loans and bundle them into mortgage securities. To analyze mortgages, S.& P. used a program called Levels version 5.6 at the time. S.& P. used that data to come up with its credit ratings for mortgage-backed bonds.

As early as 2004, S.& P. considered broadening the pool of loans in the model. The upgrade was intended to create a more realistic model called Levels 6.0, and S.& P. announced it was forthcoming. But the model was never released, the lawsuit claims.

Instead, S.& P. introduced a more modest upgrade in 2006, Levels 5.7, according to the suit. But the Justice Department contends that model did not provide an accurate picture of the loans. The suit said that an executive made a change to the model that would keep ratings artificially high.

Ms. Mathis, the S.& P. spokeswoman, said the description of the adjustment to Levels 5.7 was inaccurate. “We are not aware of any changes made to the 5.7 model that were not analytically justified, nor that any changes were made by an individual as opposed to a committee,” she said.

In addition, she said the complaint does not contain one of the important reasons that Level 6.0 was not used, namely that it would have predicted that adjustable-rate mortgages were less risky than fixed-rate loans.

Models were used elsewhere in the vast production line. As Wall Street bundled mortgages into complex securities, the banks needed high ratings to sell them to investors. Those securities, known as collateralized debt obligations, or C.D.O.’s, were especially lucrative for the credit rating agencies.

S.& P. used a model called E3 to help rate certain types of C.D.O.’s. The problem, according to the Justice Department, is that the model could turn out ratings that did not meet the issuers’ expectations.

In such cases S.& P. had a solution, the suit said. The credit rating firm switched to a different model — a more forgiving version called E3 Low — that could provide more attractive ratings on certain C.D.O.’s.

In particular, the rating agency used the model for C.D.O.’s made up of credit-default swaps, financial instruments that investors used to bet on the likelihood of loan defaults. The suit says S.& P. gave instructions on when to use E3 Low. “If the transaction passes E3.0, GREAT!!,” the instructions said, according to the government. But if it does not, “then use E3 Low.”

The lawsuit does not say who gave these instructions or how they were issued. Ms. Mathis of S.& P. said that none of the specific C.D.O.’s listed in the Justice Department’s complaint used E3 or E3 Low.