Lebanon agreed a new government on Thursday, ending months of wrangling between rival political factions that has added to concerns for its struggling economy and massive public debt.