The Senate approved legislation Thursday formally banning lawmakers and all senior federal workers from making financial trades based on information gleaned from their oversight work.

The law, which President Obama has said he will sign, will explicitly forbid lawmakers and senior administration officials from using private knowledge for personal profit. The STOCK Act — which stands for Stop Trading On Congressional Knowledge — is a scaled- back version of what was originally approved in the Senate, but will increase transparency into lawmakers’ and other officials’ finances.

The passage ended a six-year journey from a little-noticed bill to one that caught fire in recent months because of widespread anti-Congress sentiment among voters.

“We took a step toward ending the deficit of trust that’s hurting our democracy. . . . The STOCK Act will affirm that members of Congress are not above the law,” Sen. Scott Brown (R-Mass.), one of the main sponsors of the legislation, said during the debate.

Brown, who faces a strong reelection challenge from Democrat Elizabeth Warren in November, was one of many lawmakers who jumped on the bill after a “60 Minutes” report aired last fall that outlined how securities laws appear vague on the question of whether insider trading prohibitions apply to members of Congress and their staffs.

The original legislation was narrowly crafted to clarify the insider trading restrictions on Capitol Hill and require monthly disclosure of financial trades, rather than the once-a-year disclosure currently in place. The Senate debate, held over a week in early February, turned into a heated effort by rank-and-file senators to prove their reformer credentials at a time when the public has its lowest approval of Congress in polling history.

On largely bipartisan votes, the Senate included a provision to ban bonuses to senior executives at Fannie Mae and Freddie Mac; to require a burgeoning K Street sector known as the political intelligence industry to disclose its activities in the same manner as federal lobbyists; and to strengthen anti-corruption laws that the Supreme Court had ruled against as insufficiently vague. Other amendments that were offered, but not voted on, represented the toughest ethics laws ever considered on Capitol Hill, including one from Sen. Michael Bennet (D-Colo.) that would have permanently banned lawmakers and staff from becoming federal lobbyists.

The House streamlined the legislation, as House Majority Leader Eric I. Cantor (R-Va.) argued that the political intelligence provision was broadly worded and that the industry should instead be studied. In addition, the House removed anti-corruption language.

That disappointed some supporters, particularly Rep. Louise Slaughter (D-N.Y.), who first offered the insider trading legislation six years ago. In recent weeks, citing reports about the industry in the Wall Street Journal, Slaughter said she considered the intelligence disclosure the most important provision in the law.

“Despite the fact that not all of the provisions I first proposed will soon become law, today I’m delighted,” Slaughter said Thursday after the Senate vote. “I’ve learned that you’re never truly defeated in a legislature until you give up.”

While the bill is primarily aimed at members of Congress, the House and Senate also included measures to assure that the senior administration officials are covered by the insider trading ban. The Office of Government Ethics has concluded that several provisions would affect those in the executive branch who file either of two types of financial disclosure reports.

The first type, which is available publicly, applies to about 28,000 senior political appointees, career and non-career senior executives and equivalent and some uniformed military officers.

Separately, about 364,000 less-senior civilian federal employees and military officials file confidential reports that are held at individual agencies. These mainly involve positions dealing with procurement, grants and benefits administration, regulation or auditing of non-federal entities, and other duties that have an economic impact on private entities. Agencies have discretion to require confidential filing by other employees in certain other circumstances as well.

Obama has said that he will sign the bill.

Staff writer Eric Yoder contributed to this report.