British Airways and Spanish carrier Iberia signed a merger agreement on Thursday, sealing a long-awaited deal to create Europe's second largest airline by passenger kilometers.

The deal, which creates a group with a combined market value of around $7.8 billion (5 billion pounds), ends the flag carrier's long pursuit of Iberia, and will allow it to emulate rivals Lufthansa and Air France who have successfully acquired smaller peers.

The terms and conditions of the merger agreement are in accordance with the memorandum of understanding signed by both airlines in November, the companies said in a joint statement.

BA shareholders will have 55 percent of the combined firm, to be headquartered in London, while Iberia shareholders are to get 45 percent.

The two loss-making airlines hope to fly the merged entity with 408 aircraft and 200 destinations by the end of the year.

(Reporting by Tracy Rucinski and Rhys Jones; Editing by Elisabeth O'Leary)