Has a Prime Minister ever lost their seat?
Not while Prime Minister. However, Ramsay McDonald was defeated (by an official Labour candidate, himself running as National Labour) in the 1935 election, a few months after resigning as Prime Minister, and Winston Churchill, Harold Macmillan and Alec Douglas-Home all lost reelection at some point prior to becoming Prime Minister. (Churchill lost reelection as a National Liberal in 1922, before he defected to the Conservatives; Macmillan and Douglas-Home both lost in 1945.)
Many Prime Ministers failed to win election to the Commons in seats where they were not incumbents prior to becoming PM.