tl;dr
A section of the Mahābhārata narrates the story of Rāma. This section, called the Rāmopākhyāna, is far shorter than the Rāmāyaṇa which, as you correctly note, is a different epic altogether. The story as told in the Ramopākhyāna also differs in some details from the Rāmāyaṇa. The exact textual relationship between Valmiki's Rāmāyaṇa and the Rāmopākhyāna is not settled. The latter could perhaps be "an abbreviated version of the Rāmāyaṇa," for some definition of "version."
The Story of Rāma in the Mahābhārata
Book 3 of the Mahābhārata covers a period when the epic's heroes, the Pāṇḍavas, are exiled to the forest. The book is thus called the Āraṇyaka Parva or the Book of the Forest. Lamenting his plight, Yudhiṣṭhira, the eldest Pāṇḍava, asks the hermit Mārkaṇḍeya:
अस्ति नूनं मया कश्चिदल्पभाग्यतरो नरः
भवता दृष्टपूर्वो वा श्रुतपूर्वोऽपि वा भवेत् (3.257.10a–10c)
asti nūnaṃ mayā kaścidalpabhāgyataro naraḥ
bhavatā dṛṣṭapūrvo vā śrutapūrvo'pi vā bhavet
Is there any man less fortunate than I that you have seen or heard of earlier?
Mārkaṇḍeya responds with a quick summary of the story of Rāma:
प्राप्तमप्रतिमं दुःखं रामेण भरतर्षभ
रक्षसा जानकी तस्य हृता भार्या बलीयसा
आश्रमाद्राक्षसेन्द्रेण रावणेन विहायसा
मायामास्थाय तरसा हत्वा गृध्रं जटायुषम्
प्रत्याजहार तां रामः सुग्रीवबलमाश्रितः
बद्ध्वा सेतुं समुद्रस्य दग्ध्वा लङ्कां शितैः शरैः (3.258.1a–3c)
prāptamapratimaṃ duḥkhaṃ rāmeṇa bharatarṣabha
rakṣasā jānakī tasya hṛtā bhāryā balīyasā
āśramādrākṣasendreṇa rāvaṇena vihāyasā
māyāmāsthāya tarasā hatvā gṛdhraṃ jaṭāyuṣam
pratyājahāra tāṃ rāmaḥ sugrīvabalamāśritaḥ
baddhvā setuṃ samudrasya dagdhvā laṅkāṃ śitaiḥ śaraiḥ
Rāma underwent unmatched sorrow, O bull among the Bharatas! His wife Jānaki was seized by a mighty demon. Rāvaṇa, king of the demons, took her away from the hermitage through the skies, deceitfully, swiftly, having slain the vulture Jaṭāyu. Then Rāma, with the help of the powerful Sugrīva, rescued her after building a bridge across the sea and destroying Lanka with his sharp arrows.
Yudhiṣṭhira asks for details and Mārkaṇḍeya obliges with a longer version of Rāma's story.
This section of the Mahābhārata, called the Rāmopākhyāna or "the Tale of Rāma," comprises chapters 257–275 of the Āraṇyaka Parva and totals 704 verses or just above 1400 lines. While reasonably long in itself, the Rāmopākhyāna is rather brief compared to the 24,000 verses of the Rāmāyaṇa. Like the Bhagavad Gītā, the Ramopākhyāna is self-contained, but unlike the former, it has never been in wide circulation as a stand-alone text, perhaps because the story is told in such greater detail in the Rāmāyaṇa. Vernacular retellings of Rāma's story are also considerably longer than the Rāmopākhyāna. For example, Tulsidas's Rāmacharitamānas, the best-known Hindi retelling of Rāma's story, is 10,902 verses long; Kamban's Tamil version, the Rāmāvatāram, is approximately 12,000 verses long.
Is the Rāmopākhyāna an Abbreviated Rāmāyaṇa?
The story of Rāma circulates as myth and as such exists in being retold. The Rāmāyaṇa is the longest and most celebrated of these retellings. But other retellings such as Tulsidas's or Kamban's, or even the Rāmopākhyāna, do not merely summarize or abridge that epic. They are different versions of the story.
This can be demonstrated by noticing how some of the details of the Rāmopākhyāna are different from those in the Rāmāyaṇa. For example, the parentage of Rāvaṇa and his half-brother Kubera varies between the two texts. Also, in the Rāmāyaṇa, Rāma kills Rāvaṇa's brother Kumbhakarṇa, whereas in the Rāmopākhyāna the killer is Rāma's brother Lakṣmaṇa. Such variances suggest that the Rāmopākhyāna is something other than a simple summary of the Rāmāyaṇa.
There is, however, a tendency in popular culture to conflate all stories about Rāma with the Rāmāyaṇa. The Rāmāyaṇa and the Mahābhārata are considered holy books, and many if not most Hindus treat the stories they tell as literally true. Consequently, academic distinctions are moot. A scholarly question such as "How old is the Mahābhārata?" gets treated as an historical one: "When did the events described in the Mahābhārata take place?" And a textual question like “Is the Rāmāyaṇa a part of the Mahābhārata in the same way that the Bhagavad Gītā is?" is not distinguished from the very different question, "Does the Mahābhārata tell the story of Rāma?" The answer to the former is no; to the latter, yes.
Scholarly Considerations about Dating and Textual Recensions
The presence of the story of Rāma in the Mahābhārata raises a question of textual scholarship: "Is the text of the Rāmopākhyāna related to the text of the Rāmāyaṇa as we have it?" That is to say, can we relate the two texts in a way that demonstrates conclusively whether or how either one is based on the other?
This is difficult to answer with any certainty. Both the Rāmāyaṇa and the Mahābhārata were compiled over several overlapping centuries. Being about four times longer than the Rāmāyaṇa, the Mahābhārata took longer to be compiled as well. Several facts conspire to muddy the waters:
- The earliest versions of the Mahābhārata story probably predate the earliest versions of the Rāmāyaṇa, but the text as we currently have it is later than the current text of the Rāmāyaṇa.
- The Rāmāyaṇa is set some centuries prior to the Mahābhārata. This makes sense, given that Mārkaṇḍeya tells Rāma's story in the latter.
- Yet the Rāmāyaṇa includes details about the diffusion of Indo-Aryan culture over a wider geographic span than the Mahābhārata does; that suggests a later composition period than that of the Mahābhārata.
- Both epics have come down to us in several different manuscript versions grouped under two major recensions, the Northern and the Southern. The various mss. of the Rāmāyaṇa in particular vary quite widely from each other.
Due to the complex textual history of both epics, it is very hard to state authoritatively whether or not the Rāmopākhyāna derives directly from the Rāmāyaṇa. Verbal echoes between the two texts abound, however. The repetition of exact phrases implies that the two are not independent works, but related in some way. Richard Lariviere, following the scholar Albrecht Weber, lists four possibilities:
- The Rāmopākhyāna is the source for the Rāmāyaṇa
- It summarizes an early version the Rāmāyaṇa
- It derives from the Rāmāyaṇa, with the compiler of the Mahābhārata making changes to suit his own purposes
- The two stories are independently derived from a prior, unknown source.
Lariviere himself leans toward the third possibility. As Gareth McCaughan says in his answer, this view is now the most widely held; scholarly opinion tends toward the belief that the Rāmopākhyāna is a memorial reconstruction of some version of the northern recension of the Rāmāyaṇa, though it cannot be definitively linked to any extant text of that recension. (I obviously have no ability to judge the scholarship on the textual history of the Rāmopākhyāna as it relates to the Rāmāyaṇa; nevertheless, it seems worth noting that at least in the field of Shakespearean textual scholarship, it is a matter of dispute whether memorial reconstruction can be considered a viable explanation for textual variations.)
Conclusion
The Mahābhārata posits itself as a repository of every story, every adage, every character, every situation, and every human reality:
यदिहास्ति तदन्यत्र यन्नेहास्ति न तत्क्वचित् (1.56.33c)
yadihāsti tadanyatra yannehāsti na tatkvacit
The things within this may be found elsewhere; those not herein are found nowhere.
The story of Rāma is indeed found in this encyclopedic work, but to claim that the entirety of the Rāmāyaṇa is therefore contained within the text of the Mahābhārata would be mistaken.
Notes
- The proper names of the poets Valmiki, Tulsidas, and Kamban are not transliterated. Otherwise, Sanskrit quotations, words, and names are transliterated using IAST.
- Translations from the Sanskrit are my own and I am not qualified to translate Sanskrit. So YMMV, AYOR, etc.