1900 K Street, NW

Washington, DC 20006-1110

+1 202 261 3300 Main

+1 202 261 3333 Fax

www.dechert.com

Exhibit 5.1

Dechert_STAlogo_BLACKsm2

August 15, 2022

Main Street Capital Corporation

1300 Post Oak Boulevard, 8th Floor

Houston, TX 77056

Ladies and Gentlemen:

We have acted as counsel to Main Street Capital Corporation, a Maryland corporation (the “Company”), in connection with the preparation and filing of a registration statement on Form N-2 (File No. 333-263258) filed by the Company with the U.S. Securities and Exchange Commission (the “Commission”) under the Securities Act of 1933, as amended (the “Securities Act”), on March 3, 2022 (as amended as of the date hereof, the “Registration Statement”), and the final prospectus supplement (including the base prospectus filed therewith, the “Prospectus”) filed with the Commission on August 11, 2022 pursuant to Rule 424(b)(2) under the Securities Act, which relates to the issuance by the Company under the Securities Act of 1,170,000 shares (or up to 1,345,500 shares of Common Stock (as defined below) if the underwriters’ overallotment option is exercised in full) (the “Shares”) of the Company’s common stock, par value $0.01 per share (the “Common Stock”), to be sold to underwriters pursuant to an underwriting agreement, dated as of August 11, 2022, which is filed as Exhibit 1.1 to the Company’s Current Report on Form 8-K filed with the Commission on August 15, 2022 (the “Underwriting Agreement”). All of the Shares are to be sold by the Company as described in the Registration Statement and related Prospectus. This opinion letter is being furnished to the Company in accordance with the requirements of Item 25 of Form N-2 under the Securities Act, and we express no opinion herein as to any matter other than as to the legality of the Shares.

In rendering the opinion expressed below, we have examined and relied on originals or copies, certified or otherwise identified to our satisfaction, of such documents, corporate records and other instruments and such agreements, certificates and receipts of public officials, certificates of officers or other representatives of the Company and others, and such other documents as we have deemed necessary or appropriate as a basis for rendering the opinion set forth below, including the following documents:

(i)the Articles of Amendment and Restatement of the Company, certified as of the date hereof by an officer of the Company;

(ii)the Amended and Restated Bylaws of the Company, certified as of the date hereof by an officer of the Company;


Main Street Capital Corporation

August 15, 2022

Page 2

(iii)a Certificate of Good Standing with respect to the Company issued by the State Department of Assessments and Taxation of the State of Maryland as of a recent date; and

(iv)the resolutions of the board of directors of the Company, or a duly authorized committee thereof, relating to, among other things, (a) the authorization and approval of the preparation and filing of the Registration Statement, (b) the offering, issuance and sale of the Shares, and (c) the execution and delivery of the Underwriting Agreement, certified as of the date hereof by an officer of the Company.

With respect to such examination and our opinion expressed herein, we have assumed, without any independent investigation or verification, (i) the genuineness of all signatures on all documents submitted to us for examination, (ii) the legal capacity of all natural persons and the legal power and authority of all persons signing on behalf of the parties to such documents (other than the Company), (iii) the authenticity of all documents submitted to us as originals, (iv) the conformity to original documents of all documents submitted to us as conformed or reproduced copies and the authenticity of the originals of such copied documents, (v) that all certificates issued by public officials or Company officers have been properly issued and that such certificates remain accurate on the date of this letter and (vi) the accuracy and completeness of all corporate records made available to us by the Company.

As to certain matters of fact relevant to the opinions in this opinion letter, we have relied, to the extent we deem proper, upon certificates and/or representations of officers of the Company. We have also relied on certificates and confirmations of public officials. We have not independently established the facts, or in the case of certificates or confirmations of public officials, the other statements, so relied upon.

This opinion letter is limited to the effect of the General Corporation Law of the State of Maryland, as in effect on the date hereof, and we express no opinion as to the applicability or effect of any other laws of such jurisdiction or the laws of any other jurisdictions. Without limiting the preceding sentence, we express no opinion as to any state securities or broker-dealer laws or regulations thereunder relating to the offer, issuance or sale of the Shares. This opinion letter has been prepared, and should be interpreted, in accordance with customary practice followed in the preparation of opinion letters by lawyers who regularly give, and such customary practice followed by lawyers who on behalf of their clients regularly advise opinion recipients regarding, opinion letters of this kind.

Based upon and subject to the limitations, exceptions, qualifications and assumptions set forth in this opinion letter, we are of the opinion that the Shares have been duly authorized for issuance and, when issued and paid for in accordance with the terms and conditions of the Underwriting Agreement, will be validly issued, fully paid and non-assessable.


Main Street Capital Corporation

August 15, 2022

Page 3

The opinions expressed in this opinion letter (a) are strictly limited to the matters stated in this opinion letter, and without limiting the foregoing, no other opinions are to be implied and (b) are only as of the date of this opinion letter, and we are under no obligation, and do not undertake, to advise the addressee of this opinion letter or any other person or entity either of any change of law or fact that occurs, or of any fact that comes to our attention, after the date of this opinion letter, even though such change or such fact may affect the legal analysis or a legal conclusion in this opinion letter.

We hereby consent to the filing of this opinion as an exhibit to the Company’s Current Report on Form 8-K filed with the Commission on August 15, 2022 and to the reference to our firm in the “Legal Matters” section in the Prospectus. We do not admit by giving this consent that we are in the category of persons whose consent is required under Section 7 of the Securities Act or the rules and regulations of the Commission thereunder.

Very truly yours,

/s/ Dechert LLP