Scottish Coal's application to site an open-cast coal mine at Airfield Farm, near Cousland has been rejected.
It was turned down by Midlothian Council's planning committee at a meeting on Tuesday.
Campaigners against the planned mine said it was a "fantastic, victorious end to a hard-fought two year campaign".
Scottish Coal said it would be considering the company's options, including the right of appeal.
The company had wanted to extract 10,000 tonnes of coal per week for the next five years to supply coal by lorry to the nearby Cockenzie power station.
It said that if the mine got the go ahead it would create 50 jobs over five years and provide up to £500,000 for community projects over the lifetime of the site.
Among those objecting to the plans were local people who set up a protest group, Communities Against Airfield Open Cast (CAAOC), which included people from the communities in Cousland and Ormiston. It gathered more than 1,060 objections to the proposal.
Its chairman, Dougie McKenzie said: "It restored our faith in both the planning system and our councillors who have clearly listened to their electorate's concerns."
He said the decision represented the first refusal for an open-cast mine in Scotland in over five years.
Midlothian Council issued a statement which said its planning committee had agreed unanimously to reject the application on a number of grounds.
A spokesman said: "It was contrary to the structure and local plans for the area, and contrary to Scottish government planning policy as it would not have provided any benefits to the local community."
The neighbouring East Lothian Council, also raised objections. It said if the plans went ahead, it would have little practical control over noise, vibration, dust and air quality affecting East Lothian.