Liberal Democrats have won a surprise victory in an Edinburgh council by-election, taking a seat from Labour and raising questions about control of the city.