A south Alabama city has signed a deal to buy its local hospital from a Tennessee company.