Already well answered, but I wanted to try a very differnt type of answer. I had a very similar confusion which use to drive me insane, so I thought I would try giving the overly-simplified answer that would have helped me better understand the relationship between dividends, shareholders, and stocks. This example is in allot of ways overly simplified, but that's sort of the point. I want to better explain what's happening using a simplified example, in reality there are more layers of indirection but conceptually this example could be said to be the root logic behind dividends and share holders that underpine it all.
First, Companies don't pay dividends to encourage people to buy their stock! Okay, that is again overly simplified, companies are aware that the dividends they pay affect stock prices and obviously consider how one will affect the other; but conceptually that's not the primary reason that dividends exist.
Instead Dividends are the way people that already own stock ask for the company to return the money it's making to them, since as owners of the company they deserve a portion of what the company makes. In a sense the "company" doesn't want to pay stocks, but it's obligated to do so because shareholders require it.
Conceptually imagine I'm starting a company (which ideally I am in 2 weeks lol). My new company has a good idea that investors are interested in, but I need more money to pay to finish the program, buy servers, and advertise it so it can get off the ground. I go to investors and offer them stocks, part of the company, in exchange for the cash i need to start my business. I did this because it's the only way to start-up, but all those people that I gave stock to want to eventually be repaid the money they gave me, with interest.
A half decade later lets say my company is a multi dollar company. For the sake of simplicity lets say that the people i gave stocks to half a year ago still held onto them (they would no doubt have sold & re-sold them quite a few times, but effectively the logic stands even if stocks are resold, it's just a little more indirect). These people that funded me and helped me start up my company still haven't seen a penny repaid to them; and they were okay with this. They saw my company was growing and they were happy with that because the larger & faster my company grew the more it would be worth, and since they now own a part of my company the more their investiment was worth.
However, my company is no longer growning as rapidly as it use to be, and my shareholders are sick of holding on to there stock and waiting to be repaid. They instead come to me and say they want to start getting some money back, a way to repay their original investment. The way my company would do this is by payind dividends. Everyone that owns stock, all those who chipped in to help my company start up, now get a percentage of my income as repayment for their help starting my company.
Perhaps I would prefer for my company to keep growing, maybe I'm less interested in making lots of money as being famous for having a big company and putting my name on everything. I may not want to pay out dividends, because that money comes out of my company and means my company will not be able to grow as fast as I would like. However, I still have a responsibility to those that leant me enough money to help my company start to grow and if they want to finally get payed then I owe it to abide by my promise and pay them when they ask.
Every person that owns stock owns a part of my company, and they get to have a say in what I do with it. Effectively if 51% of the people holding stock out there all vote that I should pay dividends I have to pay dividends, because 51% of my company want me to. The company is as much theirs as mine after all, I may not get a say in the decision.
And thus I may find my company paying dividends. It isn't because I wanted it. Maybe I had already sold off 100% of my company stocks and as such I didn't even care what the stock value was, much less about raising it's value, I still am paying dividends to shareholders.
In reality these decisions aren't necessarily being made by a literal vote of shareholders. Instead the directory exists to do this, but he has a fiduciary duty to act in a way according to what the shareholders would vote. Thus he still needs to decide to pay out dividends when he feels it would benefit the shareholders the most, more indirect but still in keeping with the underlying concept above.