No, directly we cannot create master details relationship if custom object contains existing records.
Following are the steps to create to create master-detail relationship when records are available in custom object.
- First create field with lookup relationship.
- And then associate look field with parent record for every record
- Next change the data type of the field from look up to Master detail.