If a government cannot get its appropriation (budget) legislation passed by the House of Representatives, or the house passes a vote of "no confidence" in the government, the Prime Minister is bound by convention to resign immediately.
Following a resignation in other circumstances, defeated in an election or the death of a prime minister, the Yang di-Pertuan Agong will generally appoint as Prime Minister the person voted by the governing party as their new leader.