Bain Capital has agreed to buy Australian software maker MYOB for about A$1.2 billion ($1.3 billion) after Sage Group plc's bid ran into last-minute trouble, two sources with direct knowledge of the matter told Reuters on Saturday.

Bain and Kohlberg Kravis Roberts & Co had re-entered the race for MYOB after market turmoil derailed the UK software group's attempt to buy its Australian peer.

Private equity firms Archer Capital and HarbourVest bought MYOB, an abbreviation of the phrase 'Mind Your Own Business', for about A$450 million in 2008.

Archer, HarbourVest and MYOB were not available for comment. Bain declined to comment. The sources were not authorized to speak publicly on the matter because the deal has not been announced.

The buyout marks Bain's largest ever acquisition in Australia.

Earlier this week, Sage had entered into exclusive talks with MYOB's private equity owners, having outbid its rivals with an offer of about A$1.4 billion, the sources said. But a drop in its share price and the need for shareholder approval forced the company to abandon its bid.

That move handed the advantage to Boston-based Bain, a rival bidder for the business, competing with KKR, sources told Reuters on Friday.

The bulk of Bain's Asia assets are in Japan and Greater China. MYOB would be its third and largest Australia/New Zealand portfolio company.

The firm previously had invested in New Zealand firm Frucor Beverages and in Australian electronics company Startronics.

Bain Capital, originally led by presidential candidate Mitt Romney when the firm spun out from consulting group Bain & Co., is currently raising an up to $2 billion fund to invest in Asia.

Bain's winning bid for MYOB was backed with a A$525 million financing from Bank of America Merrill Lynch, Deutsche Bank, HSBC, Morgan Stanley, National Australia Bank, Westpac Banking Corp and UBS, according to a source familiar with the matter.

Archer and HarbourVest hired UBS AG to advise on the sale, sources have said previously.

Local private equity firm Archer has been active in dealmaking in Australia this year, as it looks to raise a new A$1.2 billion fund for investments.

The firm spent over $1 billion in six weeks earlier in the year, acquiring Quick Service Restaurant Holdings, the biggest Australian-owned fast food operator, motor sport race group V8 Supercars Australia and private hospital operator Healthcare from CHAMP Ventures.

Morgan Stanley advised Bain on the deal.

(Additional reporting by Michael Smith in Sydney.; Editing by Denny Thomas and Michael Flaherty)