EXHIBIT 5.1 LAW OFFICES Ballard Spahr Andrews & Ingersoll, llp BALTIMORE, MD 1225 17TH STREET, SUITE 2300 PHILADELPHIA, PA DENVER, COLORADO 80202-5596 SALT LAKE CITY, UT 303-292-2400 VOORHEES, NJ FAX: 303-296-3956 WASHINGTON, DC LAWYERS@BALLARDSPAHR.COM WILMINGTON, DE June 28, 2004 St. Mary Land & Exploration Company 1776 Lincoln Street, Suite 700 Denver, Colorado 80203 Re: Registration Statement on Form S-8 for Shares of Common Stock Issuable ---------------------------------------------------------------------- Under Restricted Stock Plan and Option Plans -------------------------------------------- Ladies and Gentlemen: We have acted as counsel to St. Mary Land & Exploration Company, a Delaware corporation ("St. Mary"), in connection with the filing of Post-Effective Amendment No. 1 to Registration Statement on Form S-8 (amending Registration Nos. 333-30055, 333-35352, 333-88780 and 333-106438) (the "Registration Statement") with respect to the registration under the Securities Act of 1933, as amended, of a total of 5,600,000 shares of St. Mary common stock, par value $.01 per share (the "Shares"), issuable from time to time pursuant to awards granted under the St. Mary Land & Exploration Company Restricted Stock Plan (the "Restricted Stock Plan") and upon the exercise of options ("Options") granted under the St. Mary Land & Exploration Company Stock Option Plan, as amended, and the St. Mary Land & Exploration Company Incentive Stock Option Plan, as amended (collectively, the "Option Plans") (with the Restricted Stock Plan and the Option Plans collectively referred to as the "Plans"). In that connection, we have examined, and relied upon the accuracy of factual matters contained therein, the Plans and originals and copies, certified or otherwise identified to our satisfaction, of such other agreements, documents, corporate records and instruments as we have deemed necessary for the purposes of the opinion expressed below. In giving this opinion, we are assuming the authenticity of all instruments presented to us as originals, the conformity with the originals of all instruments presented to us as copies and the genuineness of all signatures. We are also assuming that the Shares will continue to be duly and validly authorized on the dates that the Shares are issued to participants pursuant to the terms of the Plans, and, upon the issuance of any of the Shares, the total number of shares of common stock of St. Mary issued and outstanding, after giving effect to such issuance of such Shares, will not exceed the total number of shares of common stock that St. Mary is then authorized to issue under its certificate of incorporation. Based upon the foregoing, we are of the opinion that the Shares, when issued pursuant to awards granted pursuant to the terms of the Restricted Stock Plan, or upon exercise of Options granted pursuant to the terms of the Option Plans and upon payment of the option exercise price in accordance with the terms of the Option Plans, will be legally issued, fully paid and nonassessable.St. Mary Land & Exploration Company June 28, 2004 Page 2 This opinion is limited to the matters expressly stated herein. No implied opinion may be inferred to extend this opinion beyond the matters expressly stated herein. We do not undertake to advise you of any changes in the opinion expressed herein resulting from changes in law, changes in facts or any other matters that might occur or be brought to our attention after the date hereof. We hereby consent to the filing of this opinion as an exhibit to the Registration Statement. Very truly yours, /S/ BALLARD SPAHR ANDREWS & INGERSOLL, LLP