Budget Director David A. Stockman offered to resign yesterday because of what he called "careless rambling to a reporter," but President Reagan gave Stockman a second chance after the White House arranged an extraordinary self-criticism session aimed at limiting damage to the Reagan economic program.

Stockman appeared late in the day before a throng of reporters and television cameras in the White House to apologize and break the news that he had submitted his resignation during a 45-minute private luncheon with the president in the Oval Office.

His prepared statement took pains to deflect any political fallout from his words in an Atlantic Monthly magazine article away from the president and to draw all blame to himself.

Reagan made the same effort in a statement released by his deputy press secretary, Larry Speakes.

The president "expressed particular dismay at the possible suggestion that his administration -- or any members of his administration -- might seek to mislead the American public," the statement said.

Democrats have seized upon Stockman's words as evidence that the Reagan administration was selling an economic program of budget and tax cuts even though it did not believe the program would work.

For his part, Stockman said he offered to resign "because my poor judgment and loose talk have done him and his program a serious disservice. Worse, they have spread an impression that is utterly false. President Reagan believes with every ounce of his strength in his program for economic recovery, and the better opportunities it will bring to all Americans."

Stockman's mea culpa was an unusual event. Politicians seldom eat their words as publicly and as unflinchingly, but Stockman -- speaking in a voice tight with emotion -- pointed to no sinister force nor sought to make others share the blame for his trouble.

The message he and the president appeared to have agreed on was that if Stockman's credibility is to be irreparably damaged, so be it, but the president must be protected from any taint.

The statement issued on Reagan's behalf said: "He stated unequivocally that he would not tolerate any attempt to mislead the American people ; that the policies of this administration were being pursued -- and must continue to be pursued -- in good faith, on the basis of the best evidence and judgment available."

Some Stockman supporters expressed anxiety that the statement made no expression of continuing Reagan support for the budget director. Only on a not-for-attribution basis was an official willing to give Reagan's reasons for rejecting Stockman's resignation. He said the president is satisfied Stockman can and will support Reagan's programs; that Stockman is needed and his remarks do not affect the economic program; that Stockman "is an extraordinarily capable public servant" and that Republican congressional leaders favored keeping Stockman.

The tentative nature of the president's statement indicated Stockman may still be on probation. If Republican leaders find his credibility damaged beyond repair, Stockman could be forced out, despite the recognition in the White House that there is no one who can match his skills.

Stockman, who had described the Reagan across-the-board tax cuts as a "Trojan horse" to reduce the rate for wealthy taxpayers, yesterday called that "a rotten, horrible, unfortunate metaphor."

"I hesitate to use metaphors after the bad luck I've had in recent days, but I grew up on a farm," Stockman said with a small smile when asked what the president had said to him over lunch, "and I might say therefore that my visit to the Oval Office for lunch with the president was more in the nature of a visit to the woodshed after supper."

The president was "not happy," Stockman said, "and properly so."

But while Stockman took his medicine for a handful of metaphors and remarks in the long magazine article, he said the rest of the article reflected views he had made in private government meetings and in public statements over the past nine months.

It was well known that Stockman wanted to cut defense spending, reduce the cost of Social Security and other entitlement programs and avoid adding special tax breaks to the general rate cuts and accelerated depreciation for businesses that were the initial Reagan tax cut proposals.

Stockman said the magazine article resulted from "an honest, but rather large misunderstanding." He described the author, Washington Post assistant managing editor William Greider, as "an old friend of mine who has been a longtime intellectual adversary."

The 35-year-old budget director agreed to a regular series of Saturday breakfast meetings with Greider, during which he discussed the effort to form and pass the Reagan economic program.

Stockman said he understood the conversations to be off-the-record, meaning that anything Greider wrote would not include verbatim quotations.

"It is not an act of bad faith on his side or on mine," Stockman said. He said he made no objection when Greider told him he was writing an article for The Atlantic, because he expected that the article would not contain direct quotations, but he acknowledged that all the quotations are accurate.

Reagan did not read exerpts from the article until Wednesday night, according to White House sources. Even then, he took a low-key approach during the early morning.

When Republican congressional leaders held a budget session with top White House officials, the president opened the meeting by giving Stockman the floor and the budget director was applauded after briefly expressing embarrassment and chagrin.

But in mid-morning the president apparently became alarmed at the possible consequences of Stockman's words. He canceled a lunch date with Vice President Bush and summoned Stockman to the woodshed.

Senate Majority Leader Howard H. Baker (R-Tenn.) and House Minority Leader Robert H. Michel (R-Ill.) told reporters yesterday morning that Stockman would survive the damage and should stay on the job.

Baker acknowledged, however, that Stockman had caused serious political problems for Republicans. Asked what Democrats will do in the 1982 campaign with the Stockman quotes, Baker said: "Have a field day."

He added: "As a breed, nobody is more nervous about things like that than politicians. Of course, we're unhappy with the prospect that the Democrats get a free shot. They get a lick at our heads everytime we see a microphone or a camera and we're going to have that fed back to us ad nauseum."

Democratic National Committee Chairman Charles T. Manatt said Reagan should have accepted Stockman's resignation, claiming that Stockman's credibility as an administration spokesman is crippled.

"It is painfully clear that Reagan-omics is just as bad as David Stockman thought it was," Manatt said referring to the article. "Let us hope that the president recognizes the reality of this unhappy situation and drastically changes his economic course before it gets this nation into deep trouble."

Others jumped in: Sen. James J. Exon (D-Neb.) said: "Although his candor is late-blooming, there is nothing immoral about a con man repenting." He said it would help if the White House did the same.

Ex-president Ford said the Reagan program wouldn't be hurt by Stockman's remarks. "Dave's a young person and he just talked too much," Ford said. A number of Republicans rushed to Stockman's defense, including Sen. Robert J. Dole of Kansas, who wryly took note of Stockman's much-praised intellect. "I think just because he's smarter than the rest of the people in Congress doesn't mean that he's a bad guy."