By Jeffrey T. Lewis 

SÃO PAULO--Brazilian shares rose and the real strengthened against the dollar Thursday after the country's central bank surprised markets and raised its benchmark interest rate on Wednesday night.

The Ibovespa stocks index rose 1.7% to 51904 points shortly after the open. The real was trading at 2.4241 to the dollar at 10:45 a.m. São Paulo time, after closing at 2.4658 on Wednesday.

The action will help convince markets the bank is serious about getting price increases under control, and could help anchor inflation expectations going forward, economists said. Brazil's 12-month inflation rate hit 6.75% in September, above the 6.5% upper limit of the bank's target range for the indicator.

The bank's monetary-policy committee had been expected to leave the Selic rate unchanged at 11%, as it had done at the three previous meetings since raising it to that level in April. The bank said in its statement that the outlook for inflation had worsened and that the rate increase will improve the situation in 2015 and 2016.

Brazilian shares and the real have been hit in recent weeks by the country's presidential election last Sunday.

Investors preferred the business-friendly candidate Aécio Neves to President Dilma Rousseff, and ahead of the election shares fell and the real weakened when polls were released showing the president winning. Ms. Rousseff was re-elected, and shares fell again, and the real hit its weakest point in almost 10 years the day after the election.

Write to Jeffrey T. Lewis at jeffrey.lewis@wsj.com