1
                                                                     Exhibit 5.1


                          GOODWIN, PROCTER & HOAR LLP

                               COUNSELLORS AT LAW

                                 EXCHANGE PLACE

                        BOSTON, MASSACHUSETTS 02109-2881


                                                       TELEPHONE (617) 570-1000
                                                       TELECOPIER (617) 523-1231


                                      November 25, 1997


Medford Bancorp, Inc.
29 High Street
Medford, MA 02155

         Re:      Registration Statement on Form S-8
                  ----------------------------------

Ladies and Gentlemen:

     This opinion is rendered to you in connection with the preparation of the
Registration Statement on Form S-8 (the "Registration Statement") under the
Securities Act of 1933, as amended (the "Securities Act") and the prospectus
related thereto (the "Prospectus"), relating to an aggregate of 455,676 shares
(the "Shares") of the common stock, $.50 par value per share (the "Common
Stock") of Medford Bancorp, Inc. (the "Company") consisting of (i) 200,000
shares issuable upon exercise of options underlying the Company's Stock Option
Plan and (ii) 255,676 shares issuable upon exercise of options underlying the
Medford Savings Bank 1986 Stock Option Plan, which will be assumed and adopted
by the Company as the stock option plan of the Company.

     We have acted as counsel to the Company in connection with the preparation
of the Registration Statement. For purposes of this opinion, we have examined
the Articles of Organization and By-laws of the Company; such records of the
corporate proceedings of the Company as we have deemed material; the
Registration Statement and all exhibits thereto; the Company's Stock Option
Plan; the Medford Savings Bank 1986 Stock Option Plan; and such other documents
as we have deemed necessary to enable us to render this opinion.

     We are attorneys admitted to practice in The Commonwealth of Massachusetts.
We express no opinion concerning the laws of any jurisdiction other than the
laws of the United States of America and The Commonwealth of Massachusetts.

     In rendering the opinions expressed herein, we assume that all steps
necessary to comply with the registration requirements of the Securities Act and
with applicable requirements of state law regulating the sale of securities will
be duly taken.


   2
                          GOODWIN, PROCTER & HOAR LLP


Medford Bancorp, Inc.
November 25, 1997
Page 2



     Based upon and subject to the foregoing, and having regard for such legal
considerations as we have deemed relevant, it is our opinion that the Shares
have been authorized for issuance and, when issued and delivered against payment
of the consideration therefor as set forth in the Prospectus, will be validly
issued, fully paid and nonassessable.

     We hereby consent to the filing of this opinion as an exhibit to the
Registration Statement and to the reference to our name in the Registration
Statement and the Prospectus contained therein.

                                             Very truly yours,


                                             /s/ Goodwin, Procter & Hoar LLP

                                             GOODWIN, PROCTER & HOAR LLP