WASHINGTON — Ending one of the fiercest lobbying fights in Washington, Congress voted Thursday to force commercial banks out of the federal student loan market, cutting off billions of dollars in profits in a sweeping restructuring of financial-aid programs and redirecting most of the money to new education initiatives.

The revamping of student-loan programs was included in — if overshadowed by — the final health care package. The vote was 56 to 43 in the Senate and 220 to 207 in the House, with Republicans unanimously opposed in both chambers.

Since the bank-based loan program began in 1965, commercial banks like Sallie Mae and Nelnet have received guaranteed federal subsidies to lend money to students, with the government assuming nearly all the risk. Democrats have long denounced the program, saying it fattened the bottom line for banks at the expense of students and taxpayers.

“Why are we paying people to lend the government’s money and then the government guarantees the loan and the government takes back the loan?” said Representative George Miller, Democrat of California and chairman of the Education and Labor Committee.