Square announced an agreement on Thursday to buy website-building company Weebly for $365 million.

The cash-and-stock deal will allow small business customers to use both Weebly and Square to easily build websites and online stores, the companies said.

Weebly is a website-building service, similar to Squarespace or Wordpress, and was backed by Sequoia, Tencent and Y Combinator, according to Crunchbase. Weebly also competes with Medium, created by former Twitter CEO Evan Williams.

Square, run by current Twitter CEO Jack Dorsey, is a financial technology company that's best known for its eponymous square white payments devices, typically used at small businesses with iPads to read credit cards. The company, also backed by Sequoia, has had an impressive run on Wall Street this year, with shares rising nearly 35 percent year-to-date.

The merger is expected to close in the second quarter of 2018, and Weebly employees will get Square stock that vests over the next four years. Square said the deal will add recurring revenue to Square's business and help its international expansion.

Square's rapidly diversified its business recently — last week, it announced the acquisition of Zesty, a corporate catering start-up. Shares of Square rose about half a percent after the Weebly deal was announced in extended trading.

— CNBC's Deirdre Bosa and Stephen Desaulniers contributed to this report.