Follow the buy/sell provisions of the S corporation's bylaws or the shareholder buyback agreement, if one exists. Such agreements typically restrict you from selling your shares to third parties and establish an amount of money that the corporation will pay to buy back your ownership interest. This agreement is binding unless you did not consent to it or you did not adopt the terms when you became a shareholder. Additionally, a buyback agreement is not binding if it is somehow fraudulent.
Negotiate the terms of your withdrawal with existing shareholders. If an existing agreement is not in place, you should try to reach an agreement with your fellow shareholders to buy you out.
Find a third party to buy your shares. If the S corporation is unable or unwilling to purchase your shares, you have the right to sell them to a willing buyer. Assuming there are no restrictions on sale and you can't reach an agreement for the repurchase of your shares at a price you think is fair, you can sell to a third party. If restrictions exist but there’s no fixed sales price and you can't agree on a fair price, you can take the matter to court for resolution. You may have to use a secondary marketplace to sell your shares.
Draft a stock purchase agreement that outlines the terms of the sale of your stock in the S corporation, regardless of who is the buyer. Sign the agreement and sign over the shares in exchange for the purchase price. Notify the corporation of the sale of the shares and make sure the corporation sends you a final Schedule K-1, which you will need to file your personal income taxes. The K-1 details your share of profits and losses up to the date of your withdrawal.