A center-right alliance led by the Social Democratic Party has won Portugal's general election by a slender margin and is set to form a minority government that could have a difficult term in office as a radical-right populist party that came third in the voting tries to get a hand on the levers of power.