The BBC's Kevin Connolly in Washington says the first set-piece drama of the Obama era ended in a comfortable but not entirely unqualified victory for the president, who had hoped for more bipartisan support.
All 176 Republicans and seven Democrats voted against the revised package in the House. It was backed by 246 House Democrats.
In the Senate just three Republicans voted for the package.
The rebel votes were however enough under Congress rules to stop the Republican Party using blocking tactics to delay the stimulus plan, and it passed 60-38.
'Shot in the arm'
The approved version of the plan is split into 36% for tax cuts and 64% percent in spending and money for social programmes.
We have a once-in-a-generation chance to act boldly
Running to more than 1,000 pages, it includes new road building, cash to pay police in hard-up cities, and tax breaks for consumers buying houses and cars.
The package also imposes new limits on cash bonuses and other incentive compensation for executives on Wall Street, which are much tougher than those proposed by the Obama administration last week.
The provision, inserted by Senate Democrats, targets senior executives at financial institutions receiving government bail-out funds.
$240bn in tax breaks for individuals and businesses
$140bn for health care
$100bn for education
$48bn for transportation projects
Source: Associated Press
The colossal package is all to be funded with borrowed money.
Republicans had insisted on larger tax cuts instead of big spending programmes.
Republican Senate minority leader Mitch McConnell said: "This isn't Monopoly money. It's real. It adds up, and it has to be paid back, by our children and by their children."
The Democratic leader of the Senate, Harry Reid, praised the three Republicans who had voted for the bill and said it was the most important piece of legislation he had worked on.
"The country is in trouble and we're so fortunate we were able to get it passed," he said.
"It's going to give this country a shot in the arm."
Earlier, Mr Obama had said that in the longer term the government needed to rein in spending, and that "we are going to have to once again live within our means".
The president told members of the Business Council in Washington that the package was "only the beginning of what I think all of you understand is going to be a long and difficult process of turning our economy around."
"We have a once-in-a-generation chance to act boldly, and turn adversity into opportunity, and to use this crisis as a chance to transform our economy for the twenty-first century," Mr Obama said.
Among the measures in the approved package is a "Buy American" clause that had caused alarm among US trading partners.
The EU and Canada said that provisions favouring American-produced materials for government projects risked provoking retaliatory protectionist measures.
In the face of this reaction, the clause was softened to a version requiring the government not to violate trade agreements.
Last week, the House had approved an earlier $825bn version of the package without any Republican support.
The Senate voted to approve a different $838bn version on Tuesday, with few Republicans opting to back it.
The two versions had to be reconciled in a joint House-Senate committee before facing final votes in the two chambers.
President Obama increased the pressure on Congress this week, saying he wanted the bill on his desk ready to sign by the weekend.
The BBC is not responsible for the content of external internet sites.
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.