By Maria Carolina Marcello

BRASILIA (Reuters) - Brazil President Michel Temer won another victory on Tuesday in his effort to restore fiscal discipline when the lower house of Congress approved a constitutional amendment to cap spending for 20 years.

Heavy public spending, a recession and a massive corruption scandal rocking Brazil's political establishment undermined confidence in South America's biggest economy last year and stripped the country of its investment-grade rating with creditors.

The constitutional amendment would limit the growth of public spending to the rate of inflation of the previous 12 months for up to 20 years. It passed by 359-116 votes, receiving seven votes less than it did in a first-round vote. The house has yet to vote on six suggested changes to the text before it can send the amendment to the Senate for approval.

While the government easily won the vote - it needed 308 votes to pass - the smaller margin pointed to the challenge Temer faces in enacting an unpopular belt-tightening agenda.

The spending ceiling, which can be revised after 10 years, is a drastic measure to plug a budget deficit that ballooned to more than 10 percent of gross domestic product last year.

Temer, who replaced leftist Dilma Rousseff in August after her impeachment trial for breaking budget laws, vowed to restore credibility to Brazil's finances and pull out of its worst recession since the 1930s Great Depression.

The new president and many economists argue that limiting government spending is crucial for Brazil to curb a growing debt burden that could top 73 percent of GDP this year.

Opponents of the cap, led by the Workers Party, sought to block approval, saying it would reduce education and health services for those who most need them and cut spending needed to revive a moribund economy and fight double-digit unemployment. Demonstrators protesting against the measure were removed from the gallery.

To reduce opposition to the spending ceiling in Congress, the government agreed to postpone any spending cap on health and education until 2018.

Confidence that Temer can put the books in order and turn the economy around has placed Brazilian assets among the best performing investments in the world this year. The real currency has strengthened 26.7 percent this year and closed on Tuesday at 3.10 to the dollar, its highest in 15 months.

Finance Minister Henrique Meirelles said the government is confident the Senate would pass the spending cap by mid-November without changes, which would send the proposal back to the lower house for approval again.

Meirelles said the proposed cap has already helped boost the Brazilian economy and urged lawmakers in a video statement not to reduce the 20-year duration of the measure because it will take years to bring the public debt under control.

"Approval of the amendment as it stands will be an important signal to economic agents, consumers, investors and businessmen that Brazil is serious about the fiscal problem and committed to undertaking reforms needed to restore growth," he said in the statement released before the vote.

Meirelles said Brazilian and foreign companies are already dusting off plans to invest in the country again.

(Writing by Anthony Boadle; Editing by Sandra Maler and Lisa Shumaker)