NEW YORK (AP) — Halliburton is buying rival oilfield services company Baker Hughes is a cash-and-stock deal worth $34.6 billion.

The deal comes shortly after talks had stalled and Halliburton prepared to go hostile with its takeover bid.

The transaction is valued at $78.62 per Baker Hughes Inc. share, a 31 percent premium to its Friday closing price of $59.89. Baker Hughes shareholders will receive 1.12 Halliburton shares plus $19.00 in cash for each share they own.

The companies put the deal's enterprise value at about $38 billion.

The boards of both Houston companies approved the deal unanimously and it's targeted to close in the second half of 2015. Shareholders and regulators must still sign off on the tie-up.

Baker Hughes's stock rose more than 16 percent in Monday premarket trading.

Copyright 2014 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.