Lam Research's ( LRCX) second-quarter profit almost doubled, beating Wall Street's estimate, as both revenue and margins improved.

The chip-equipment maker's earnings rose to $122.1 million, or 84 cents a share, from $66.5 million, or 47 cents a share, a year earlier.

"Ongoing income," which excludes the tax expense on the repatriation of earnings, totaled $139 million, or 96 cents a share. Analysts expected earnings of 83 cents a share on this basis, according to Thomson First Call.

Revenue increased to $525.6 million from $353.8 million, beating Wall Street's target of $506.5 million. The company also posted improved gross margins, which rose to 52.2% from 50.2% the prior quarter due to the revenue growth, product mix and improved factory utilization.

"We are pleased with the results for the June quarter," said Steve Newberry, Lam's president and chief executive, in a statement. "Our market-share gains and the increased capital investment by our customers drove our new orders substantially above expectations."

Despite the beat, Lam shares were moving lower in after-hours trading. The stock recently fell 97 cents, or 2.2%, $43.97.