Japan's ruling coalition lost its parliamentary majority as voters punished the Liberal Democratic Party over a funding scandal and a cost-of-living crunch.