Japan's Sharp Corp. on Thursday agreed to a takeover by Taiwan's Foxconn, a source familiar with the matter said, in what would be the largest acquisition by a foreign company in Japan's insular technology sector.

The Taiwanese firm, known formally as Hon Hai Precision Industry Co., has offered to invest 659 billion yen ($5.9 billion) in Sharp, sources have previously said.

Sharp's board earlier concluded a two-day meeting to discuss whether to accept an offer by the world's largest contract electronics manufacturer over a rescue by a state-backed investment fund.

The source, who was not authorized to speak on the matter, declined to be identified. A Sharp spokesman declined to comment. Foxconn also declined to comment.

Shares in the ailing electronics maker briefly rose over 5 percent but pared gains to last trade flat.

Century-old Sharp was once a highly profitable manufacturer of premium TVs and a favored screen supplier to Apple. But it has struggled in recent years as massive investments in advanced LCD plants backfired amid price competition with Asian rivals.

The deal comes after five years of courting by Foxconn founder Terry Gou, who sees ownership of Sharp as a way to better compete with Asian rivals such as Samsung Electronics Co.

Sharp's liquid crystal display (LCD) panel technology is expected to help consolidate Foxconn's position as the world's biggest assembler of Apple Inc's iPhones and iPads.

For Sharp, Foxconn's ample funds will help stabilize its finances while the Taiwanese company's global sales channels could help improve sales.

(Reporting by Makiko Yamazaki; Editing by Edwina Gibbs)