MADRID—Spanish lawmakers will decide on Friday whether to oust Prime Minister Mariano Rajoy and replace his center-right government with one led by the center-left Socialist Party, a confidence vote that has injected a dose of uncertainty into Spanish politics and spooked some investors.

Spanish lawmakers will debate Mr. Rajoy’s future on Thursday in Madrid and then vote on Friday to remove or keep in power his minority government, the president of Spain’s parliament said on Monday. Spain’s main opposition party, the center-left...