DUBAI (Reuters) - Emirates agreed to buy its first Boeing BA.N 787 Dreamliners in a last-minute, $9 billion deal at the Dubai Airshow on Wednesday while reducing its order for the U.S. planemaker's delayed 777X model.

The deal for 30 787-9 Dreamliners is part of a $25 billion shake-up of the airline’s fleet involving overhauls of orders from both Boeing and Airbus as it reshapes its fleet to prepare for the demise of the soon-to-be-scrapped Airbus A380.

Emirates, the launch of customer for the 777X, will now take 126 of the long-range widebody jets, down from a planned 150, after tense negotiations on a parallel 787 deal that at one stage looked set to elude Boeing.

Emirates and Boeing announced the order on day four of the Middle East’s biggest aerospace event after lawyers put finishing touches to the deal the same morning.

“The 787s will complement our fleet mix by expanding our operation flexibility in terms of capacity range and deployments,” Emirates Chairman Sheikh Ahmed bin Saeed al-Maktoum told reporters at the airshow.

The deal resolves a complex set of interlocking Boeing deals with Emirates, the largest buyer of wide-body jets.

In a two-stage swap, Emirates will upgrade its six remaining orders for the current 777-300ER model to the larger 777X to bring its order total to 156. Then it will swap 30 of these for the newly ordered Dreamliners, which have a lower price tag.

The 777X has run into delays and Emirates says it no longer knows when it will get its first plane, which was supposed to be delivered in 2020. Boeing has said the 777X will be delivered from 2021.

Emirates will receive its first Dreamliner in 2023, around the time the airline expects to resume expansion which has recently slowed as passenger demand shrinks.

Slideshow ( 3 images )

“We want to introduce it on to some of the thinner routes where the 787 comes on to its own both on the medium and long-haul operations,” Emirates President Tim Clark said.

Boeing also secured deals for 60 of its 737 MAX airliner at the Dubai Airshow, including its first firm orders since the plane was grounded eight months ago.

The Emirates order was seen as a message of support for the troubled U.S. planemaker which has been weakened by the 737 MAX crisis, analysts said.

Emirates at its home airshow also revised deals with Boeing's European rival Airbus AIR.PA.

Emirates ordered 50 Airbus A350s on Monday in a $16 billion revised deal that means it is dropping consideration of the smaller A330neo, at least for the time being.

The United Arab Emirates, which includes Dubai, is a close ally of the United States. Tensions between Iran and U.S.-backed Gulf Arab states provided a tense backdrop to the airshow.