Answer
Rajoy's government was ousted in 2018 through a vote of no confidence. This occurred after a series of corruption scandals involving members of his party came to light, eroding public trust in his leadership. The motion was brought forward by the Socialist Party and supported by other opposition parties, leading to Rajoy's resignation and the subsequent formation of a new government.